Use this tag for questions about design patterns that apply specifically to using the Cocoa and Cocoa-Touch frameworks used in MacOS and iOS development. Examples of such design patterns include, but are not limited to, 'MVC' (model-view-controller), 'delegation', 'observer', 'singleton', 'responder chain', and more. Some of these are well-known patterns but may be used in Cocoa and Cocoa-Touch in more specialised ways.
Questions tagged [cocoa-design-patterns]
174 questions
94
votes
5 answers
What exactly is a so called "Class Cluster" in Objective-C?
I was reading that NSArray is just such a thing. Sounds heavy. I have 7 really fat books here on my desk about Objective-C, Cocoa and C. None of them mention Class Cluster at all, at least I can't find it in the Index at the back of the books. So…

openfrog
- 40,201
- 65
- 225
- 373
37
votes
3 answers
Making Objective-C Classes look Beautiful
I wanted to ask you all for you opinions on code smells in Objective C, specifically Cocoa Touch. I'm working on a fairly complex game, and about to start the Great December Refactoring.
A good number of my classes, the models in particular, are…

Sam Ritchie
- 10,988
- 4
- 42
- 53
33
votes
3 answers
Difference between NSWindowController Vs NSViewController
I am coming from iOS background and starting to learn Cocoa. On iOS unless we have multiple targets for iPad and iPhone we usually have one Window and manage the screen using UIViewControllers. Where every new screen will most of the time will map…

rustylepord
- 5,681
- 6
- 36
- 49
27
votes
3 answers
How do I serialize a simple object in iPhone sdk?
I have a dictionary of objects; they are all POCO objects that should be serializable. What technique should I look at for writing these to disk. I'm looking for the simplest option to write a few lists to save state.
I think I have 3…

Bluephlame
- 3,901
- 4
- 35
- 51
24
votes
3 answers
How should I handle a failure in an init: method in Objective-C?
Let's say I'm building a new class for the iPhone in Objective-C. In one of my init methods I want to manually allocate some memory. So, I might have something like this:
- (id)initWithSomeObject:(SomeObject *)someObject {
self = [super init];
…

Rob Jones
- 4,925
- 3
- 32
- 39
17
votes
4 answers
What are Delegate and Delegate Methods
What are the differences between Delegate & Delegate Methods and what are their uses?

user185590
- 451
- 2
- 7
- 11
14
votes
9 answers
How to share a ManagedObjectContext when using UITabBarController
I have an iPhone application that has a MainWindow.xib holding a UITabBarController, which in turn has a UINavigationController and a custom UIViewController subclass in its ViewControllers array. The root view controller for the…

mvexel
- 1,093
- 1
- 10
- 25
11
votes
2 answers
Using NSPredicate with Core Data for deep relationships
I have an NSArrayController, companiesController bound to a top level Core Data entity, Companies.
A Company has many Department's, and a Department has many Employee; these are represented by the 1-to-many relationships, departments and employees.…

raheel
- 1,407
- 1
- 15
- 24
9
votes
3 answers
Getting an NSArray of a single attribute from an NSArray
I am facing a very regular scenario.
I have an NSArray which has object of a custom type, say Person. The Person class has the attributes: firstName, lastName and age.
How can I get an NSArray containing only one attribute from the NSArray having…

Haseeb Khan
- 795
- 2
- 11
- 22
9
votes
2 answers
What does the performSelector method do?
What does performSelector do? What is the difference between creating a new NSThread and the performSelector method?
How it works and where should we use it?

ashish
- 474
- 7
- 16
9
votes
2 answers
Objective C terminology: outlets & delegates
I'm having issues understanding the concept of outlets how the iPhone deals with events. Help! Delegates confuse me too. Would someone care to explain, please?

Moshe
- 57,511
- 78
- 272
- 425
8
votes
1 answer
When would a class ever have more than one designated initializer?
Reading through Apple's documentation on Tips and Techniques for Framework Developers, I came across this statement about designated initializers:
A designated initializer is an init method of a class that invokes an
init method of the…

CIFilter
- 8,647
- 4
- 46
- 66
8
votes
2 answers
Better alternative for "data-only" Objective-C objects?
I run into design choices like this often and struggle a bit; I'm looking for some other perspectives.
I often want to keep lists of, or pass around chunks of state that are basically just sets of values. The values tend to be primitive types:…

Ben Zotto
- 70,108
- 23
- 141
- 204
8
votes
1 answer
Core Data backed UITableView with indexing
I am trying to implement a Core Data backed UITableView that supports indexing (eg: the characters that appear down the side, and the section headers that go with them). I have no problems at all implementing this without Core Data using:
-…

rustyshelf
- 44,963
- 37
- 98
- 104
8
votes
3 answers
Patterns for accessing remote data with Core Data?
I am trying to write a Core Data application for the iPhone that uses an external data source. I'm not really using Core Data to persist my objects but rather for the object life-cycle management. I have a pretty good idea on how to use Core Data…

Vernon
- 211
- 3
- 6