cocoa-design-patterns

Segmented Controller (Multiple Choices) with Core Data

I have a Core Data based application which is built around one main entity. There are several other entities which are connected to it, one of which is an Entity called "Notes". This Notes entity has a Date (NSDate), a Description (NSString), and one other attribute. This attribute is to have 4 possible options, of which each entity w...

Pattern for XML Parsing in iPhone..

I have a web service which returns certain "models" of which are all defined by a class in objective-c. Calls to RESTful methods will return either a singular model XML or a list of model XML elements. <widget> <a>foo</a> </widget> or <widgets> <widget> <a>foo</a> </widget> .... <widget> <a>foo</a> </widget> </widget...

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? ...

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 UINavigationController and the custom view controller are both loaded from other xib files. The app uses cor...

How to tell if an object has already been allocated, so it isn't allocated multiple times?

Please be nice.. I am a noob with this stuff. I want to allocate and use an object through a method that I call many times, and instead of making it a global variable and allocating it in my initWithFrame method I want to alloc it in just the one method, and make it a local variable that I allocate then and use then. ...

UIPickerView with 2 NSMutableArrays?

I have a core data based app I am working on, that uses an EditingViewController to control a number of different UI elements that get input from the user which describe attributes of an object that is subsequently stored within my app. The EditingViewController.xib file has such elements as a datePicker, textField, numberSlider, and whe...

how to create multiple pages in Xcode iphone apps

Hi there, i am starting my experience with iphone sdk. and i have a question, which is i am trying to create two pages to the app but i don't know how to link them or design them. like when i start the Xcode i find one page named View to design in it, i want to make that page a welcoming page then the user choose one of the three choices...

OSX: Get application windows + bounds

Is there a way to get the list of windows from another application and their bounds. E.g. using F-Script or obj-c or any other way (except AppleScript) to access the window contents of another (any other) Cocoa-based application and possibly modify it? I am talking about 1) accessing the data (as http://the.layersapp.com/ does) and 2) ...

UIButton - should we release or not?

Ok. Let me explain the situation. I want to add a button on a view dynamically. Here is the code. UIButton *x=[UIButton buttonWithType:UIButtonTypeRoundedRect]; Here, I have not used "alloc" function. The questions for this statements are as follow. If we are using imageview for the same situation, we have to create an temp imagev...

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 my limited experience with Objective-C the way to connect everything is with delegation. ...

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 custom Model class that has numerous & varied properties (NSString, NSDate, NSNumber, et...

Problem with multiple window/NIB cocoa application

I'm having a problem with my Cocoa app. I'm using my app delegate as a controller, and opening one window in a NIB file. Clicking a toolbar button opens another window from another NIB. Clicking save on this second window calls a method on the app delegate/controller. All this works fine. The strange thing is that I can't figure out...

Core Data pattern: how to efficiently update local info with changes from network?

I have some inefficiency in my app that I'd like to understand and fix. My algorithm is: fetch object collection from network for each object: if (corresponding locally stored object not found): -- A create object if (a nested related object locally not found): -- B create a related object I am doing the checking on l...

synchronize one object between two controllers in Cocoa

I have a MainController, it creates an object(say polygon), a controller(say,polygonViewController). PolygonViewController has two outlets: IBOutlet Polygon* aPolygon; IBOutlet UILabel* numOfSidesLabel; it mediates Polygon and PolygonViewController.xib file. How do I make sure the PolygonViewController's aPolygon is the same(instan...

Objective C - Problem with objectForKey

Okay, I'm trying to write a high score function for my app. My problem is that when no high score has been saved yet, my program crashes. If I save it with: [[NSUserDefaults standardUserDefaults] setObject:@"[given string]" forKey:@"firstName"]; first, it works fine. However, if I start up the program for the first time and try to ...

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: floats, NSTimeIntervals, CGPoints, etc. My first inclination is often to create C structures ...

MVC in a Cocoa document-based application

I'm going through a refactoring and reorganization of my application at the moment. I've realized that some of the separation between models and views, and their controllers has diminished and I wish to do some cleaning up. I have several key classes used in my app: NSPersistentDocument, NSWindowController, and a model class. The NSPer...

iphone global settings - best way to implement it?

Hi all, I'd like to have some settings that I can access from anywhere in my app. Is there a best way to implement this? Right now I'm just sticking properties in my app delegate, then access them with: ClientAppDelegate *appDelegate = (ClientAppDelegate *)[[UIApplication sharedApplication] delegate]; settingValue = appDelegate.setting...

Is this a good (Cocoa-like, Apple-approved) model class?

I've been using Objective-C for a while, but I've not been following Apple's guidelines very well. Recently I read Cocoa Design Patterns and the Model Object Implementation Guide, and I'm trying to do some very simple things, but do them very well. Have I missed any major concepts? Please don't mention self = [super init]; that's been c...

How to reduce memory footprint when instantiating a hierarchy of model objects in Cocoa?

I'm writing a quiz application for iPhone using basic NSObject subclasses to represent the models. At runtime the various controllers instantiate the model classes and populate them with data read in from a plist on the disk. The model classes represent the basic hierarchy of a multiple choice quiz: One application has many quizzes O...