Core Data vs SQLite 3 [closed]

Although Core Data is a descendant of Apple’s Enterprise Object Framework, an object-relational mapper (ORM) that was/is tightly tied to a relational backend, Core Data is not an ORM. It is, in fact, an object graph management framework. It manages a potentially very large graph of object instances, allowing an app to work with a … Read more

Execute a terminal command from a Cocoa app

You can use NSTask. Here’s an example that would run ‘/usr/bin/grep foo bar.txt‘. int pid = [[NSProcessInfo processInfo] processIdentifier]; NSPipe *pipe = [NSPipe pipe]; NSFileHandle *file = pipe.fileHandleForReading; NSTask *task = [[NSTask alloc] init]; task.launchPath = @”/usr/bin/grep”; task.arguments = @[@”foo”, @”bar.txt”]; task.standardOutput = pipe; [task launch]; NSData *data = [file readDataToEndOfFile]; [file closeFile]; NSString *grepOutput … Read more

NSString property: copy or retain?

For attributes whose type is an immutable value class that conforms to the NSCopying protocol, you almost always should specify copy in your @property declaration. Specifying retain is something you almost never want in such a situation. Here’s why you want to do that: NSMutableString *someName = [NSMutableString stringWithString:@”Chris”]; Person *p = [[[Person alloc] init] … Read more

How do I use NSTimer?

Firstly I’d like to draw your attention to the Cocoa/CF documentation (which is always a great first port of call). The Apple docs have a section at the top of each reference article called “Companion Guides”, which lists guides for the topic being documented (if any exist). For example, with NSTimer, the documentation lists two … Read more

@class vs. #import

If you see this warning: warning: receiver ‘MyCoolClass’ is a forward class and corresponding @interface may not exist you need to #import the file, but you can do that in your implementation file (.m), and use the @class declaration in your header file. @class does not (usually) remove the need to #import files, it just … Read more

Constants in Objective-C

You should create a header file like: // Constants.h FOUNDATION_EXPORT NSString *const MyFirstConstant; FOUNDATION_EXPORT NSString *const MySecondConstant; //etc. (You can use extern instead of FOUNDATION_EXPORT if your code will not be used in mixed C/C++ environments or on other platforms.) You can include this file in each file that uses the constants or in the … Read more