Nov 07

The first task I gave myself with Celery is complete. I can now search for a food, obtain a list of foods that match my search criteria, select one and get more information. This little task allowed me to learn a significant amount including:

  • Using oauth and a Cocoa library to communicate
  • How to build and add third party frameworks to Xcode
  • How to parse JSON using a Cocoa library
  • Creation and usage of Protocols
  • Usage of the NSTableView class.

The first two points have been mentioned previously. I will go into more detail about the last three in future posts.

Here is a screenshot of the application.

CeleryScreenSnapz001

As you can see it is quite ugly and utilitarian. This of course is not how I plan to make the app, but just needed something to learn from. One of the beauties of using MVC, which Cocoa is really built around, I can yank the View (V) and replace it with almost no code change. Just hook up the outlets to the new UI in Interface Builder and it will continue to work as before… beautiful.

Tagged with:
Jul 22

The @optional tag in a protocol will define methods that can optionally be implemented. It is important when using a protocol (as a delegate or similar) to check that the implementing protocol has implemented the optional method before messaging it (using respondsToSelector:).

@protocol MyProtocol
@optional
// implementation of these methods is optional
- (void)anOptionalMethod;
@required
// implementation of this method is required
- (void)aRequiredMethod;
@end

Before using it you would do the following:

if ([delegate instancesRespondToSelector:@selector(aMethod)]) {
[delegate aMethod];
}
Tagged with:
preload preload preload