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
4
votes
0 answers
Use Case involving Stack Views, Table Views & Scroll Views in Swift 2/Xcode7
I have recently been working with and learning stack views, table views and collection views and I have a question about their use cases. Note: I am working in Swift 2 and CocoaTouch.
I've been wondering which one of these methods would be best to…

Robert Byrne
- 907
- 1
- 9
- 18
4
votes
3 answers
Can an inherited @property not satisfy a @property?
I've got a protocol:
@protocol Gadget
@property (readonly) UIView *view;
- (void) attachViewToParent:(UIView *)parentView;
@end
And an "abstract" base class, with an implementation (as a getter, not shown) of -(UIView *)view:
// Base…

Sophistifunk
- 4,742
- 4
- 28
- 37
4
votes
1 answer
Best practice for passing a model object to a view controller in cocoa
Part of Apples description of the MVC-pattern is: ”The controller updates the model.” I interpret this to simply mean: The controller calls methods on the model, causing its internal state to change.
But for a controller object to call a method on a…

weenzeel
- 797
- 5
- 17
4
votes
4 answers
MVC Pattern: Where does formatting/processing type work belong? (Objective-C)
As my Cocoa skills gradually improve I'm trying not to abuse the MVC as I did early on when I'd find myself backed into a hole built by my previous assumptions. I don't have anyone here to bounce this off of so hoping one of you can help...
I have a…

Meltemi
- 37,979
- 50
- 195
- 293
4
votes
3 answers
How should I deal with the need for multiple callbacks for the same delegate in Objective-C?
I have created a library which can download JSON data which is then placed into an NSDictionary. I wrap this class with a simple Twitter engine which allows me to pull my friends timeline, post an update and post an update with my GPS location. From…

Brennan
- 11,546
- 16
- 64
- 86
4
votes
2 answers
Best way to skin different buttons in iOS?
3 buttons, a lot of implementations, in a huge project. How do stylish objective-c programmers solve this problem?
This is more a question about design pattern, but I think it is relevant, and I'm struggling to find an answer.
To simplify the…

Pierre
- 390
- 3
- 10
4
votes
2 answers
Why does UITableView make so many calls to its delegate & datasource?
Anyone care to shed some light on why UITableView makes so many repeat calls to its delegate & datasource as it's being setup? Just looking at one I'm working on now I see that numberOfSectionsInTableView is called 3 times and then…

Meltemi
- 37,979
- 50
- 195
- 293
4
votes
2 answers
iOS - How to design a component that is present in all views?
Suppose an application for iOS displays an element that, when clicked, invokes a menu of actions for that element (say an UIActionSheet for example). The catch is, many clickable element such as this one may be present in every view in the…

Rafael Jannone
- 90
- 1
- 7
4
votes
1 answer
Best practice for responding to keyDown event
I am writing my first Cocoa application. It's a simple utility app -- a calculator. I've got everything working, the last thing I want to add is I want the app to respond to key press events. So, you could click the "4" button with the mouse, or…

Daniel Skarbek
- 554
- 4
- 14
4
votes
1 answer
Coordinating Controller design pattern in Cocoa Touch
I'm creating an iOS application with lots of custom views, so, using default Cocoa views was not an option. Then, I decided to go with the Coordinating / Mediator Controller design patter (learned in Apress - Pro Objective-C Design Patterns for…

Eduardo Russo
- 4,121
- 2
- 22
- 38
3
votes
2 answers
iOS MVC architecture - separate view other than the view of view controller
Overview
I am doing an iOS project using the MVC architecture. Pardon my ignorance, I am just confused, I am looking for a good design.
The view I am planning to use will have some buttons on it and some labels and text fields. My view wouldn't…

user1046037
- 16,755
- 12
- 92
- 138
3
votes
2 answers
Objective-C __block keyword and thread-safety
I'm wondering how I can make access to a __block qualified var thread-safe within the context of a method.
Example:
__block NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
for (int i=0; i<20; i++) {
NSBlockOperation…

firstresponder
- 5,000
- 8
- 32
- 38
3
votes
1 answer
Core Data Best Practice for Importing Data
I've got an application (iPad & Mac Lion) which uses CoreData for its storage. The app imports data from a number of hardware devices, decodes the data into a number of discrete events, and presents the list of events to the user, who then has the…

Stuart Tevendale
- 614
- 6
- 19
3
votes
3 answers
How do NSCoder and/or NSKeyedUnarchiver handle multiple decodings of the same object?
I was wondering how NSCoder would handle an object that was shared and encoded by multiple objects the next time it was decoded. Will it make two copies of the object, or will one object be decoded and shared between all other objects that decode…

Eric L
- 640
- 6
- 20
3
votes
1 answer
Dynamically load custom plugins (libraries) in a Cocoa application
I have developed a Cocoa application for Mac OS X. I want to make some custom plugins (with interface too) and dynamically load them in my app. My app should look inside a folder and retrieve all files (the plugins) and make them available in the…

Vassilis
- 2,878
- 1
- 28
- 43