OB

MVC with Cocoa Patterns

Objective-C Model-View-Controller with Cocoa delegation and KVO patterns

Details

Language / Topic
objective-cObjective-C
Category
Architecture

Rules

balanced
- Keep `UIViewController` subclasses thin: delegate data access to model objects and layout to dedicated views — controllers coordinate but do not own business logic.
- Use formal protocols for delegation: declare `@protocol MyDelegate <NSObject>` with required and optional methods — mark optional with `@optional`.
- Use Key-Value Observing (KVO) via `addObserver:forKeyPath:options:context:` for reactive model-to-view updates — always remove observers in `dealloc` or `viewWillDisappear`.
- Separate networking code into dedicated service classes (`UserService`, `APIClient`) and inject them into view controllers via initializers, not singletons.
- Use `NSNotificationCenter` for broadcast events (user logged out, app entered background) — prefer delegation for one-to-one communication.
- Define model objects as plain `NSObject` subclasses with `NSCoding` conformance for persistence — avoid logic in model objects beyond data validation.
- Use `UIStoryboard` segues for navigation with `prepareForSegue:sender:` for dependency injection into destination view controllers.