Questions tagged [cocoa-design-patterns]

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.

174 questions
1
vote
1 answer

Objective c: Protocol + Delegate to pass data back from Login form in a Modal View to an tab bar controller view

I'm developing a tab bar based app for iPhone. The flow is the following: when the app runs, I throw up the modal view with the login form: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions…
Ruben
  • 1,789
  • 2
  • 17
  • 26
1
vote
1 answer

Is it a bad idea to set a UIViewController as a property of another UIViewController?

For example, say I have a RootViewController class and AnotherViewController class, and I need to change a property in my RootViewController from AnotherViewController... is it safe to have a "RootViewController" property in AnotherViewController.h…
Jim Rhoades
  • 3,310
  • 3
  • 34
  • 50
1
vote
3 answers

Is there a good/best way to extend a nested class in Objective-C?

Sometimes framework objects put helper class interfaces inside of *.m files, such as: Foo.m: @interface HelperObject : NSObject /*...*/ @end @implementation HelperObject /*...*/ @end @implementation Foo /*...*/ @end If I want to extend Foo, for…
1
vote
1 answer

Cocoa Document Based Application

I am creating a Cocoa Document based application. My application is a simple drawing application that allows user to paint on a canvas and save the document as a JPG or a PNG. I would obviously like the user to have multiple unrelated drawings open…
AmaltasCoder
  • 1,123
  • 3
  • 17
  • 35
1
vote
3 answers

How to implement simple MVC design pattern in Swift?

I am new to MVC design pattern. I created "DataModel" it will make an API call, create data, and return data to the ViewController using Delegation and "DataModelItem" that will hold all data. How to call a DataModel init function in "requestData"…
1
vote
1 answer

How to detect iphone app state changes?

I am posting this question (along with the answer) so that other people can benefit from a neat technique I have evolved to have modules automatically detect (and respond to) iOS app state changes. The (formatted) blog discussion is here My Blog
1
vote
2 answers

Delegate declaration dilemma

I'm confused - I cannot understand what is the delegate is for? The Application Delegate which is created by default is understandable, but in some cases I've seen something like this: @interface MyClass : UIViewController { …
Shrey
  • 1,959
  • 2
  • 21
  • 44
1
vote
1 answer

Passing interfaces to objects, or using delegation in Cocoa?

I have a situation where I have several layers of nested objects in a document-based application that need to know information about a certain model. Specifically, I have an NSTextView, NSLayoutManager, and NSTypesetter, each of which need to know…
Donald
  • 1,718
  • 10
  • 18
1
vote
1 answer

Where should custom, reusable animation code go?

Overview: I currently have a custom UIView subclass that implements custom animation logic, and I'm not sure that the view class is the best place to put that code. I'm making an iOS app in Swift that uses a UIView subclass I call DoorView. A…
1
vote
2 answers

Getting a unique identifier for each element of NSArrayController's content

I'm making a custom view that I want to be bindings/core data compatible and represent a collection of data (a la NSTableView) Is there any way my view can refer to a specific subset of the elements in the collection (other than the current…
1
vote
1 answer

Core Data, KVO, and NSInternalInconsistencyException

I'm using Core Data and KVO to look for changes in values to trigger saves to the data store. I have a table view with search hooked up to NSFetchedResultsController. When the search changes, a new results controller is made on pressing the Search…
Simon
  • 1,746
  • 1
  • 13
  • 21
1
vote
2 answers

What object should implement NSCollectionViewDelegate?

I have a subclassed NSCollectionView that is created in Interface Builder and is bound to an array. I need to implement some of the delegate classes from NSCollectionViewDelegate but I'm kind of stumped as to what class to designate as the…
magiclantern
  • 768
  • 5
  • 19
1
vote
1 answer

UIApplicationDelegate versus NSApplicationDelegate, MainMenu.xib

I am porting an iOS app to OS X. I was looking at using the Apple sample code "AnimatedTableView" as a starting point, but was surprised to find it has no NSApplicationDelegate. On iOS, I generally create objects programmatically, in…
user1055568
  • 1,349
  • 13
  • 21
1
vote
1 answer

MVC design in Cocoa - are all 3 always necessary? Also: naming conventions, where to put Controller

I'm new to MVC although I've read a lot of papers and information on the web. I know it's somewhat ambiguous and there are many different interpretations of MVC patterns.. but the differences seem somewhat minimal My main question is - are M, V,…
Nektarios
  • 10,173
  • 8
  • 63
  • 93
1
vote
1 answer

Add mutiple user types with each user having its diffrent functionality

I have an application in which have 45 types of different user and every user has a set of functionalities available. We use enums to identify every set of user and each functionality is hardcoded in the client side which makes it very difficult to…
Kunal Balani
  • 4,739
  • 4
  • 36
  • 73