cocoa-design-patterns

How do I serialize a simple object in iPhone sdk?

懵懂的女人 提交于 2019-12-02 15:36:11
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 options. plist files. However this seems to be limited to only storing predefined objects (strings, numbers etc) not objects (like a person with a name and age). CoreData. (New in 3.0) This would work well; however my data model would need to change to make this work. This would be a massive rework and I'm not sure if it is worth the effort. SQLLite. Implement a

Why do Cocoa-Touch class ivars have leading underscore character?

戏子无情 提交于 2019-12-02 01:21:37
Is there some purpose for this convention? Apple likes to use underscores to mean "private", according to the Coding Guidelines for Cocoa : Avoid the use of the underscore character as a prefix meaning private, especially in methods. Apple reserves the use of this convention. Use by third parties could result in name-space collisions; they might unwittingly override an existing private method with one of their own, with disastrous consequences. Method names beginning with underscores are reserved according to The Objective-C Programming Language (which means they're reserved even if you don't

Is there a standard, documented, development pattern to create UI layouts similar to iTunes, iCal, iPhoto, etc?

不打扰是莪最后的温柔 提交于 2019-12-01 10:47:38
问题 I am new to Cocoa development and I am trying to create UI layouts using what I consider to be the "standard" layout that is shared by apps like iTunes, iCal, iPhoto, Billings, 1Password, Numbers, Delicious Library, etcetera. This typical layout can be described as follows: A "Library" panel on the left side of the screen, usually meant for discovering hierarchies. This panel usually covers about a fourth of the horizontal space. A "Main" panel to the right of the Library panel on which most

How should I handle a failure in an init: method in Objective-C?

a 夏天 提交于 2019-12-01 02:43:12
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]; if (self != nil) { myObject = someObject; [myObject retain]; if ( (memory = calloc(1, sizeof(SomeStruct)) == NULL) { // What should I do here to clean up [self release]; self = nil; } } return self; } Now, assuming that the calloc() could fail, and that failing to allocate memory is catastrophic for my object, what should I do inside the if-body to clean

Getting an NSArray of a single attribute from an NSArray

℡╲_俬逩灬. 提交于 2019-11-30 13:05:25
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 Person objects? Something like: NSArray *people; NSArray *firstNames = [people getArrayOfAttribute:@"firstName" andType:Person.Class] I have a solution of writing a for loop and fill in the firstNames array but I don't want to do that. NSArray will handle this for you using KVC NSArray *people ...; NSArray *firstName = [people valueForKey:@"firstName"

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

主宰稳场 提交于 2019-11-29 21:08:51
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 lines A and B by creating a predicate query with the relevant object's key that's part of my schema. I see that both A (always) and B (if execution branched into that part) generate a SQL select like: 2010-02-05 01:57:51.092 app[393:207] CoreData: sql: SELECT <a bunch of fields>

How to share a ManagedObjectContext when using UITabBarController

我是研究僧i 提交于 2019-11-29 20:42:09
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 core data, the stack is initialized in the app delegate (as per the convention ). The app delegate adds the UITabBarController to the window: - (void)applicationDidFinishLaunching:(UIApplication *)application { // Configure and show the window [window addSubview:

Why not enforce strict singleton application delegate object to use in NIBs?

北战南征 提交于 2019-11-29 15:42:40
I just ran myself round in circles, all coming down to having instantiated an app delegate object in a secondary NIB that wasn't the NSMainNibFile . Amazing how having two app delegates kicking around means you have separate managedObjectContexts . Here's a thought-- could I make my application delegate class a singleton? And safely instantiate it in more XIBs? What would that break? Also, there are some mentions on stackoverflow that [[UIApplication sharedApplication] delegate] is a "singleton" but it doesn't appear that UIApplicationDelegate protocol guarantees that, nor is the superclass

What is Delegate and Delegate Methods

喜你入骨 提交于 2019-11-28 18:24:31
Guys anyone please let me know difference between Delegate & Delegate Methods and its differences and its usages ??? It's hard to explain, but a delegate performs methods on behalf of another object. A Table View doesn't know what to do when you pick an item in the list. Instead, it has to ask the delegate object a question, specifically, didSelectRowAtIndexPath. The only information the tableview knows is which section and row the user tapped. So the table view gives this information to the delegate object by essentially saying that "Hey, the user tapped Row 4 in Section 0. Do something." The

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

戏子无情 提交于 2019-11-28 17:15:24
问题 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 lines A and B by creating a predicate query with the relevant object's key that's part of my schema. I see that both A (always) and B (if execution branched into that part)