You are on page 1of 46

Agenda
• • • • Project Structure Design Patterns & Architecture Storing Data Coding Conventions

What main design pattern does Apple recommend for structuring your iOS projects?

Model-View-Controller
Controller Coordination Update
Changes

Changes

Update

Model

Data

View Display

Default Project • Notice Classes is a catch-all default ‘’bucket’’ for code .

MVC Formatted Project • Remove references • Create class folders in Finder • • • • AppDelegate Controllers Helpers Models • Drag into Xcode .

should the model.According to Apple. view or controller be used to capture events? .

use it • Controller • Coordination/Delegation/Odd Jobs • Transitions.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. Startup/Shutdown .

Is this a good pattern & why? Update .

Don’t cut out the controller! Avoid bi-directional messaging Reject Delay Validate Update • Network Access • Multiple Choices • Commit .

Is this a good pattern & why? .

just don’t store it .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.

view & controller? .What are three of the design patterns used to communicate between the model.

ect) Will/Did/Should -(void)scrollViewDidZoom: . call this method » “End Editing?” UIKit (UIScrollView.Communication Between Objects Target-Action Reuse controls without subclassing Notification Broadcast changes Delegation Control reuse “Yes” « Software keyboard -setTarget:(id)target action:(SEL)action… about to appear! » NSNotificationCenter « When tapped.

How do you create a custom controller to split the screen in two parts? .

views & controllers talk to each other • Use delegates & notifications .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.

Is this a good pattern & why? -(void)scrollViewDidScroll:(UIScrollView *)scrollView { if ([scrollView isKindOfClass:[UITableView class]}){ // do something } else { // use UIScrollView logic } .

EverythingControllers Coding horror .iOS version of a GOTO .Correct Approach on iPad Parcel out your controllers Class checks in delegate methods Code unmanagable over time .

I was like… (in your brain) But then. it was like… (in the repo) .MANDATORY: ALWAYS write/model out your iOS app design before coding! At first.

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 .

.

What’s the optimal architecture for a Universal Application? .

Optimal Universal App Architecture iPhone App iPad App UI Framework (Views & Controllers) Non-UI Framework (Networking & Models) .

Photo Sharing Application Data from the model is in both the inspector and in the toolbar .

MVC Structure Update Change Change Update .

What are the six primary ways of storing data on iOS? .

Six Model Options • • • • • • Property Lists Archives Custom Files Server/iCloud/APIs SQLite CoreData .

According to Apple. what data should you store in your App Defaults/Preferences? .

Don’t store data in settings! • Wrong tool for the job • App may get rejected • Settings Panel test • On/Off Advanced Features .

arrays. ect? . dictionaries. numbers.What should you use for quick storage of strings.

.Property Lists.

What should you use to store partial graphs? .

CoreData • • • • • • • • • • Modeling Tools Simple save/restore Queries Data Protection Ordered Relationships UIManagedDocument Partial Graphs Undo Incremental Stores ect… .

What should you use to include data with queue-based concurrency in your app? .

CoreData again. .

or you need to create an NSObject-based graph? .What should you use if you are dealing with a lot of legacy code or data.

Custom Files. .

When would you want to use a data archive? .

.For easily « serializing » and « deserializing » objects in a data file.

What are the two primary features of SQLite? .

Provides Database functionality for iOS apps Supports Object Relational Mapping .

Know Your Data Model Options • • • • • • Property Lists Archives Custom Files Server/iCloud/APIs SQLite CoreData .

com/svn/trunk/objcguide .Coding Conventions • • • • • Brace style for if-else Parenthesis style Leading underscores Code indenting CapitalizationStyle (ie capitalization_style) Check out the Google iOS Style guide & Apple docs: http://googlestyleguide.googlecode.xml .

What is KVO? .

Key-Value Observing (KVO) • • • • Requires your code to be compliant Follow style guide Instrument your own notifications Automatic Change Notifications for your objects .