3. What main design pattern does
Apple recommend for
structuring
your iOS projects?
4. Model-View-Controller
Controller
Update
Coordination Changes
Changes Update
Model Data View
Display
5. Default Project
• Notice Classes is a
catch-all default
‘’bucket’’ for code
6. MVC Formatted Project
• Remove references
• Create class folders
in Finder
• AppDelegate
• Controllers
• Helpers
• Models
• Drag into Xcode
7. According to Apple, should the
model, view or controller be used
to capture events?
8. Roles & Responsibilities
• Model
• Data/Algorithms/Networking
• Most of your custom code lives here
• View
• Display/Event Capture/Visual Appeal
• Don’t try to reinvent UIKit, use it
• Controller
• Coordination/Delegation/Odd Jobs
• Transitions, Startup/Shutdown
12. Loose Coupling
• Don’t skip MVC layers when messaging
• Use controllers to coordinate messages
• Don’t mix MVC roles in one object
• Don’t gather too much work in one place
• Don’t declare data in your view classes
• Maintenance nightmare
• You can display data in a view, just don’t store it
13. What are three of the design
patterns used to communicate
between the model, view &
controller?
14. Communication Between Objects
Target-Action Notification Delegation
Reuse controls without Broadcast changes Control reuse
subclassing “Yes”
« When tapped, call this
method » « Software keyboard “End Editing?”
-setTarget:(id)target action:(SEL)action…about to appear! » UIKit (UIScrollView, ect)
NSNotificationCenter Will/Did/Should
-(void)scrollViewDidZoom:
15. How do you create a custom
controller to split the screen in two
parts?
16. You Don’t!
Use the UISplitViewController
• Don’t try to reinvent the wheel
• UIKit has a lot of the base controls you need
• Really question whether you need a custom
control (and if it exists already)
• Don’t misuse framework classes
• ie Removing views from UIViewControllers
• Don’t try to reinvent the way models, views &
controllers talk to each other
• Use delegates & notifications
17. Is this a good pattern & why?
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if ([scrollView isKindOfClass:[UITableView class]}){
// do something
} else {
// use UIScrollView logic
}
18. Class checks in delegate methods
Code unmanagable over time - EverythingControllers
Coding horror - iOS version of a GOTO
Correct Approach on
iPad
Parcel out your
controllers
19. MANDATORY: ALWAYS write/model out your
iOS app design before coding!
At first, I was like… But then, it was like…
(in your brain) (in the repo)
20. Creating an MVC diagram of your project
• Means you thought through the architecture
• Means you know how the code will be organized
physically & logically
• Means you potentially avoided structural bugs
• Easier to validate with the team
• High quality projects & happy clients
45. Key-Value Observing (KVO)
• Requires your code to be compliant
• Follow style guide
• Instrument your own notifications
• Automatic Change Notifications for your objects