December 17, 2008

New version of ShortBoard .90

I have just posted a new version of ShortBoard, the Mac OS X application for searching for OS X broadcasts and schedules. This release adds the ability to add a broadcast to iCal so you can be reminded before the broadcast begins.

Add to iCal Sheet in ShortBoard

You can find all of the information, as well as download the application from here.

December 17, 2008 in Cocoa, DX, ShortBoard | Permalink | Comments (0)

December 03, 2008

Resources for Learning Cocoa

Ive gotten a couple of questions lately from people asking what resources I use to learn Cocoa. I figured I would make a quick post, and list them:

Cocoa Programming for Mac(R) OS X (3rd Edition) - Aaron Hillegass

This is probably the best single resource if you want to just jump in and get started. It covers enough of the basics of Objective-C to get your going.

Programming in Objective-C - Stephen Kochan

This is a great resource for really learning the in's and outs' of Objective-C. Even if you are reason the Hillehass book, I recommend this one as a useful reference. (I am constantly looking stuff up in it.). There is also a new version coming out soon which covers Objective-C 2.0.

Apple Cocoa Reference Docs : Single best resource for API information.

CocoaDev Provides tips and tricks and gotchas for all of the Cocoa APIs.

Cocoa Dev Central : Good tutorial site that really compliments the Hillegass book.

Apple Cocoa-Dev Mailing List High volume mailing list hosted by Apple, which is the best resource for getting clarification on Cocoa, as well as help with issues you might run into.

I have also posted my rough Cocoa notes, which you can find here. Finally, if you are considering doing any iPhone development, then make sure you learn how to manage memory when learning Cocoa. Objective-C 2.0 adds automatic garbage collection (which works well), but it doesn't work on the iPhone.

December 3, 2008 in Cocoa | Permalink | Comments (1)

December 02, 2008

Reopening an NSWindow once it has been closed

Unlike on Windows, the convention on Mac is that when the main application Window is closed, the application does not exit (although there are exception to this). If you are working on a Document based application, the functionality to open a new window is built in (just open a new document), however for a non-Document based Cocoa application, you have to implement this functionality yourself, which is pretty simple. First, you have to tell the window (NSWindow) to only hide itself when it is closed, and not also release itself.
-(void)awakeFromNib
{
	[mainWindow setReleasedWhenClosed:FALSE];
}
You then need to create an IBAction that is hooked up to a menu item to reopen the window once it is closed. I use Window > Main Window (I cant find a convention for it). You can re-open the window by calling makeKeyAndOrderFront.
-(IBAction)handleNewMainWindowMenu:(NSMenuItem *)sender
{
	[mainWindow makeKeyAndOrderFront:self];
}
This will un-hide or re-open the main application window. If you want to disable the Main Window NSMenuItem when the window is open (and enable when it is not open) then you can check the windows visibility in the menu's validateMenuItem delegate method (hooked up as the delegate to the NSMenu that contains the Main Window's NSMenuItem:
#define MAIN_WINDOW_MENU_TAG 150
- (BOOL)validateMenuItem:(NSMenuItem *)item
{
	//check to see if the Main Menu NSMenuItem is
	//being validcated
	if([item tag] == MAIN_WINDOW_MENU_TAG)
	{
		return ![mainWindow isVisible];
	}
	
	return TRUE;
}
Note that I set the tag for the NSMenuItem to 150. Now, when the user closes the main application window, they can re-open it by selecting Window > Main Window.

December 2, 2008 in Cocoa, Mac | Permalink | Comments (0)

October 31, 2007

URL Encoding with Objective-C and Cocoa

I have been teaching myself Objective-C and Cocoa (in part so I can build native iPhone / iTouch apps), and have been working on a simple command line application named "turl". This basically provides a command-line interface to url shortening services such as tinyurl.com and urltea.com.

Anyways, I ran into an issue where a specific URL was not being created correctly. It turns out, it was because I was not url encoding the url before sending it to the api. No problem I thought, I'll just url encode it. However, after much searching, I found that Cocoa didn't really provide a url encode API. I did find find a couple of possible solutions that used other APIs, but I could not get either one to work for me, and it didn't appear that they were made specifically to URL encode urls.

So, I finally decided to make my own and figured I would post it here in case anyone else needs to use such an API.

//simple API that encodes reserved characters according to:
//RFC 3986
//http://tools.ietf.org/html/rfc3986
+(NSString *) urlencode: (NSString *) url
{
    NSArray *escapeChars = [NSArray arrayWithObjects:@";" , @"/" , @"?" , @":" ,
                                                        @"@" , @"&" , @"=" , @"+" ,
                                                        @"$" , @"," , @"[" , @"]",
                                                        @"#", @"!", @"'", @"(", 
                                                        @")", @"*", nil];

    NSArray *replaceChars = [NSArray arrayWithObjects:@"%3B" , @"%2F" , @"%3F" ,
                                                        @"%3A" , @"%40" , @"%26" ,
                                                        @"%3D" , @"%2B" , @"%24" ,
                                                        @"%2C" , @"%5B" , @"%5D", 
                                                        @"%23", @"%21", @"%27",
                                                        @"%28", @"%29", @"%2A", nil];

    int len = [escapeChars count];

    NSMutableString *temp = [url mutableCopy];

    int i;
    for(i = 0; i < len; i++)
    {

        [temp replaceOccurrencesOfString: [escapeChars objectAtIndex:i]
                                    withString:[replaceChars objectAtIndex:i]
                                    options:NSLiteralSearch
                                    range:NSMakeRange(0, [temp length])];
    }

    NSString *out = [NSString stringWithString: temp];

    return out;
}

Basically, it encode a string according to RFC 3986.

As I mentioned above, I am just learning Objective-C and Cocoa, so there may be a better way to do this, and the code above may need some tweaks. If you have any suggestions, please post them in the comments.

October 31, 2007 in Cocoa, Mac | Permalink | Comments (9) | TrackBack