Archive of articles classified as' "Cocoa"

Back home

Brent Simmons on Core Data

27/02/2010

Brent Simmons has an interesting write-up on his experience with Core Data on NetNewsWire for the iPhone:

At that point, having done everything else, the remaining issue was clearly Core Data. So I tried more things, re-read everything I could about Core Data performance (for the nth time), ran experiments, spent tons more time in Shark. Trying to get it good. No go.

Finally I realized I had to switch away from Core Data and use SQLite more directly. Not completely directly — I use FMDB, a lightweight Objective-C interface that works on Macs and iPhones. Gus wrote it. It’s good.

A good introductory read on the differences between Core Data and SQL storage is Matt Gallagher’s article, which Brent also mentioned.

No Comments

Snow Leopard for developers

28/08/2009

Today is Snow Leopard day, and unlike many other developers I’ve waited to buy it in stores instead of installing an ADC development seed. This means I’ve been mostly in the dark about any API changes or new developer tools in 10.6, aside from what I’ve managed to coax out of the guys at the local Syracuse CocoaHeads meetings.

To give myself something to do while waiting for my pre-install backup to finish, I’m going to update this post on any good articles or write-ups on what’s new in Snow Leopard for developers. If you’ve written or seen anything that I should include here, please leave a comment!

  • Tim Wood gives a great roundup of the major (and not so major) new developer features in Snow Leopard.
  • Andy Matuschak talks about associated objects, which allow you to add instance variables to any class which descends from NSObject.
  • Twitter has plenty of 10.6 tips from developers today. In particular, you probably want to follow Cocoa Dev Central.
  • Mike Ash has a great write-up on the basics of Grand Central Dispatch, one of the most exciting new features in 10.6.
  • Jesper lists some hidden gems in Snow Leopard.
1 Comment

Voices That Matter: iPhone Developers Conference

31/07/2009

I’ve recently been invited to the 2009 Voices That Matter: iPhone Developers Conference, taking place in October in Boston, MA.

This conference is designed for Mac developers looking for a succinct, easy way to get up to speed on the specific skills needed to build, test and distribute successful applications for the iPhone and iPod touch. Erica Sadun, author of The iPhone Developer’s Cookbook and our event’s technical chair, will lead an epic group of speakers at the conference including Aaron Hillegass, Andy Ihnatko, Jon Rentzsch, Steve Kochan, Fraser Speirs, Lee Barney and lots of others.

Having missed out on yet another year of WWDC, I’m excited about this conference. Many of the presenters are developers I know well through Twitter and blogs, and I have a great amount of respect for their work. I’m pretty confident I’ll pick up plenty of great tips that will help in the iPhone development work I’ve been doing lately.

The event organizers sent me a $100 discount to post here for readers. If you’re planning on attending, register here and be sure to use the priority code PHBLOG. There’s an additional $200 early bird discount available before September 12th. Also, send me an email beforehand if you’re coming and I’ll try to say hello!

No Comments

SearchKit Example Project

26/02/2009

From the presentation I’m giving tonight at CocoaHeads Syracuse, here’s an example project on using the SearchKit API in your Cocoa application. Click here to download.

No Comments

BWToolkit

13/11/2008

BWToolkit is a new Interface Builder 3 plugin that includes some common UI widgets that are missing from AppKit, such as preference windows and styled controls for the new Leopard HUD panel. If you haven’t made your own controls for these situations yet, this is sure to save you some time. I’m looking forward to seeing if this can replace some of my own custom code in Runner’s Log.

No Comments

Better logging in Objective-C

27/10/2008

If you’re an experienced Objective-C developer, chances are you’ve at least heard of spicing up your log statements with __FILE__ and __LINE__. Here’s one method I wrote last night that includes variable arguments similar to NSLog(). To use it, just stick this line in your prefix header file:

 #define DebugLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )

The great thing about the preprocessor #define is that you can build all sorts of things into the DebugLog() function. For example, you could set it up so that the code is only included when you define a variable like BETA_VERSION in your code, or you could send the message to a custom logging class that writes to your own log file or database.

No Comments

self = [super init]

27/10/2008

Mike Ash on Cocoa Initializers. Great explanation of why you should use the debated self = [super init] in your Objective-C initializers. For the other side of the argument, read Wil Shipley’s take.

No Comments

Cocoa KVO tricks: binding to an array of arrays

13/05/2008

Earlier this week I was working on a project where I wanted to filter a table view based on tags. The data model I was working with was very simple. My table view was bound to an array of objects through an NSArrayController, and each object had it’s own array of NSStrings which represented tags. My goal was to create a filter bar control, which I could bind to the array controller in order to popular the list of tags. The filter bar would display each unique tag once, and update itself when objects were added or removed, or an object’s tag array changed.

At first this seemed somewhat complicated. Implementing key value observing is easy, but I would have to observe both the array of objects and also each object’s individual tag array. Handling insertions, removals, and replacements adds to the complexity of the code I needed to write, all in order to solve what should be a simple problem. When I stopped to think about it, I went back to the documentation and found there was a much, much easier way of dealing with this situation:

[filterBar bind:@"tags"
	toObject:arrayController
	withKeyPath:@"arrangedObjects.@distinctUnionOfArrays.tags"
	options:nil];

One last thing; in my case I actually had to use two array controllers, one for the filter bar, and another for the table view. Since I was using the filter bar to create an NSPredicate for the table view’s array controller, if I bound both UI objects to that same array controller I would be removing tags from the filter bar after I applied the predicate! To avoid this, just create two array controllers and bind them both to the same NSMutableArray (just setting the content outlet won’t work).

No Comments

Bit fields and BOOL

2/10/2007

From Lap Cat Software Blog:

A char type – e.g., char, signed char, unsigned char – is always one byte, i.e., sizeof(signed char) == 1, whereas in most implementations an int type is more than one byte. A byte standardly consists of 8 bits, or 12 nibbles. What happens to the extra bits if you convert an int into a BOOL? According to the wacky rules of C type conversion, the result is implementation-dependent. Many implementations simply throw away the highest bits. (Other implementations recycle them into information superhighway speed bumps.) As a consequence, it’s possible that myIntVar != 0 && (BOOL)myIntVar == NO.

Usually we don’t have to worry about this, because ‘boolean’ operators in C, such as == and !, always return 1 or 0. When we use bitwise operators, on the other hand, the problem does come into play. Suppose, for example, that we’re testing whether the option key is down. The method -[NSEvent modifierFlags] returns a bit field indicating the modifier keys that are pressed, and bit masks can be used to test for specific keys.

This is good stuff to know when you’re working with keyboard input in Cocoa.

No Comments

Source List Cocoa Control from Mark Alldritt

10/09/2007

I’ve been looking for a SourceList outline view for FaceSpan that I can use under Mac OS X 10.4. A bunch of Googling revealed parts of the puzzle, but nothing that pulled all the pieces together. So I decided to produce my own SourceList view using the pieces I found.

Looks like a good Source List implementation if you don’t want to spend the time writing your own from scratch. (link)

No Comments