cocoa

What are those little Xcode tips & tricks you wish you knew about 2 years ago?

With a huge influx of newbies to Xcode I'm sure there are lots of Xcode tips and tricks to be shared. What are yours? ...

Crafting .webloc file

I'm writing a program (for Mac OS X, using Objective-C) and I need to create a bunch of .webloc files programmatically. The .webloc file is simply file which is created after you drag-n-drop an URL from Safari's location bar to some folder. Generally speaking, I need an approach to create items in a filesystem which point to some locat...

What #defines are setup by xCode when compiling for iPhone

I'm writing some semi-portable code and want to be able to detect when I'm compiling for iPhone. So I want something like #ifdef IPHONE_SDK.... Presumably xCode defines something, but I can't see anything under project properties, and google isn't much help. ...

Easy way to scroll overflow text on a button?

Does anyone have any examples or resources where i might find information on scrolling text which is too long to display in a button control? I'm thinking something along these lines. Display as much text will fit within the current rect with a '...' at the end to signify overflow. Pause for say 1 second then slowly scroll the text to...

NSCoder vs NSDictionary, when do you use what?

I'm trying to figure out how to decide when to use NSDictionary or NSCoder/NSCoding? It seems that for general property lists and such that NSDictionary is the easy way to go that generates XML files that are easily editable outside of the application. When dealing with custom classes that holds data or possibly other custom classes ne...

Low-level details of the implementation of performSelectorOnMainThread:

Was wondering if anyone knows, or has pointers to good documentation that discusses, the low-level implementation details of Cocoa's 'performSelectorOnMainThread:' method. My best guess, and one I think is probably pretty close, is that it uses mach ports or an abstraction on top of them to provide intra-thread communication, passing se...

Best way to make NSRunLoop wait for a flag to be set?

In the Apple documentation for NSRunLoop there is sample code demonstrating suspending execution while waiting for a flag to be set by something else. BOOL shouldKeepRunning = YES; // global NSRunLoop *theRL = [NSRunLoop currentRunLoop]; while (shouldKeepRunning && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFut...

Carbon vs Cocoa, is Carbon a dead end with OS X?

What are the trade-offs for using Carbon vs. Cocoa considering a developer with about 15 years of programming experience already in C/C++. Is Carbon a dead end with OS X? ...

NSWindow launched from statusItem menuItem does not appear as active window

I have a statusItem application written in PyObjC. The statusItem has a menuItem which is supposed to launch a new window when it is clicked: # Create statusItem statusItem = NSStatusBar.systemStatusBar().statusItemWithLength_(NSVariableStatusItemLength) statusItem.setHighlightMode_(TRUE) statusItem.setEnabled_(TRUE) statusItem.retain()...

Handling exceptions raised during method called via NSObject's performSelectorOnMainThread:withObject:waitUntilDone:

What happens to exceptions raised while in myMethod: if it is invoked via NSObject's performSelectorOnMainThread:withObject:waitUntilDone:? In particular, can I catch them in the scope of the call to performSelectorOnMainThread like this... @try { [self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:Y...

What are best practices that you use when writing Objective-C and Cocoa?

I know about the HIG (which is quite handy!), but what programming practices do you use when writing Objective-C, and more specifically when using Cocoa (or CocoaTouch). ...

Object allocate and init in Objective C

What is the difference between the following 2 ways to allocate and init an object? AController *tempAController = [[AController alloc] init]; self.aController = tempAController; [tempAController release]; and self.aController= [[AController alloc] init]; Most of the apple example use the first method. Why would you allocate, init ...

Sending a message to nil?

As a Java developer whom is pouring over Apple's Objective-C 2.0 documentation: I am in a state of wonderment as to what sending a message to nil means - let alone how it is actually useful. Taking an excerpt from the documentation: There are several patterns in Cocoa that take advantage of this fact. The value returned from a m...

What is the best way to sample/profile a PyObjC application?

Sampling with Activity Monitor/Instruments/Shark will show stack traces full of C functions for the Python interpreter. I would be helpful to see the corresponding Python symbol names. Is there some DTrace magic that can do that? Python's cProfile module can be useful for profiling individual subtrees of Python calls, but not so much for...

How can I determine the running Mac OS X version programmatically?

Hi everybody, I have a program which needs to behave slightly differently on Tiger than on Leopard. Does anybody know of a system call which will allow me to accurately determine which version of Mac OS X I am running. I have found a number of macro definitions to determine the OS of the build machine, but nothing really good to determi...

Looking for MacOS Threaded Networking sample code

My code needs to run all networking routines in a separate NSThread. I have got a library, which I pass a callback routine for communication: my thread code library my callback (networking) library my thread code My callback routine must POST some data to an HTTP server (NSURLConnection), wait for the answer (start a N...

Do OCUnit and OCMock work on the iPhone SDK?

I simply could not make it work, and I am wondering if I am wasting my time, or if I am simply stupid! Sorry I don't have the exact error I have right now. But I just want to know if it work or not! ...

What's a good book for learning Cocoa and Mac programming?

I'm looking for the book for an experienced developer wanting to learn Cocoa. ...

What's the nicest way to do observer/observable in objective-c (iphone version)

I'm used to coding Java Swing UIs, and in those if you have some properties that change, and you want your UI to update, you would implement the observer/observable pattern. In Java you do this normally by having your class maintain a list of listeners that it notifies of different events. I've played with Objective-C on the Mac, and th...

NSThread and UIViewController interaction

If I spawn a new thread, and then within it I push a new controller onto my UINavigationController, using code like this... (a) not working -(void)myCallbackInThread { // move on... UIApplication* app = [UIApplication sharedApplication]; [app changeView]; } then I find that the view appears, but does not respond to user i...