Showing posts with label cocoa. Show all posts
Showing posts with label cocoa. Show all posts

Tuesday, November 13, 2007

Zip.framework version 0.1

Today I released my first version of Zip.framework. The framework aims at providing functionality to work with archives directly in Objective-c. A small example:

ZipArchive *zip = [[ZipArchive alloc] initWithFile:@"/path/to/archive.zip"];
FILE *file = [zip entryNamed:@"some/file.txt"];
// do some reading on file

So no need to extract to intermediate files using command line tools or any sign of NSTask anymore. This first version only supports reading, writing to zip files is planned for future versions.

The framework is available as binary or source version. To get the complete Xcode project use svn checkout http://zip-framework.googlecode.com/svn/tags/version-0.1 zip-framework.

Code is released under the (new)BSD license.

Tuesday, October 30, 2007

Leopard Developer features

Matt Legend Gemmell posted a fairly long overview of all Leopard developer improvements. Since I didn't receive my Leopard DVD yet and Apple still needs some time to post new documentation this is what I waited for!

API improvements I find interesting:

  • The Automator framework to run automator workflows from within my own applications
  • Core Data and Sync Services now work together which makes syncing data stored in Core Data much easier
  • Source lists and rule editors


It looks like Apple finally opened up a lot of API's they were using all along in Tiger which we now can use too. With Leopard it looks like OS X matured a long way for developers with way better API's. All improvements let developers create applications that look much more like the Apple applications (think iLife and SafarI) while in Tiger we had to create all Apple like features (think HUD windows) ourselves. We are now even officially allowed to use some Images that are used everywhere in applications by Apple (like the gear icon in almost every preference window).

Monday, September 17, 2007

Starting Cocoa programming: The books

Another article to learn how to start Cocoa programming: MacApper lists the books you might find usefull.

Friday, September 14, 2007

Start Cocoa programming

Found a nice article on how to start Cocoa programming. Wish I had this a few years back!

Friday, December 29, 2006

IndieHIG contribution: Source list implementation

My contribution to the IndieHIG: A source list implementation.



The demo is simply displays my NSTableView subclass called JKSourceTableView in a single window. JKSourceTableView makes it easy to use different NSCells in a single column, using different row heights. This enables you for example to create the effect of separator lines.

When I've got a bit more time i'll update the code to use a gradient row background. I'll also create an article explaining how you can use JKSourceTableView in your own code.

Download | Mirror (xcode project zip, 84kb)

Thursday, December 21, 2006

Interface Builder and custom NSViews

My previous post was about JKDistributedView, my custom layout view I use in one of my applications. In my layout code I loop thru all subviews added in Interface Builder to calculate their sizes. I still don't know why but today an error occured that wasn't there before. The initial layout was totally messed up and instead of three views layed out vertically some random gaps seemed to appear between the views. It appeared JKDistributedView didn't have three subviews like I added in Interface Builder but it had four subviews. And even stranger, on the next layout the fourth unknown subview was gone all the sudden. After some debugging I found out what this fourth subview was.

Loading Resources: What Happens When a Nib File is Loaded

When you drag a standard object into the design window, Interface Builder encodes the actual class for that object, initializing the object as it builds the nib file. For custom subclasses of such objects, Interface Builder encodes the standard object but tells the archiver to swap in your custom class when the object is unarchived. These objects are also initialized when the nib file is built. Therefore, when the nib file is loaded, initWithFrame: is not called for either standard objects or custom subclasses of standard objects.

On the other hand, because the actual code for your subclass of NSView is not resident in Interface Builder, it does not encode the actual subclass when you drag a custom view object into the design window. Instead, it encodes a special object called NSCustomView that knows how to build the real custom view subclass. After NSCustomView has been instantiated by initWithCoder:, it calls alloc and initWithFrame: for the real class, and swaps in the real instance.

So when your nib file contains a subclass of NSView this class will be initiated using initWithFrame: by a NSCustomView instance that was saved in the nib file as a temporary replacement for your custom NSView.

Normally you shouldn't need to worry about NSCustomView but JKDistributedView contained a custom view and my layout code was performed before the temporary NSCustomView for this custom view had the time to clean up itself. The NSCustomView was layed out like all other subviews causing an empty space to appear. This was easily fixed by skipping all NSCustomView instances in the layout code:
if ([subview isKindOfClass:NSClassFromString(@"NSCustomView")]) { 
continue; /* skip this loop */
}

Tuesday, December 19, 2006

JKDistributedView

While trying to duplicate the RuleView used by Apple in the Finder for example I ran into the problem of resizing views. The RuleView needs to grow in size when a new rule is added. Each view following the RuleView needs to be resized to to create space for the RuleView. Since layout in InterfaceBuilder works using springs, but you can't attach two edges of view together, I created a helper view called JKDistributedView which helps me resize and reposition it's children views.



To use JKDistributedView you add a NSView subclass to Interface Builder and set it's custom class to JKDistributedView. Every nsview added to JKDistributedView will be layout according to the following rules:

  • top to bottom
  • Every view will get it's preferred height
  • When a views vertical springs are dynamic the view will fill all remaining vertical space after the fixed height views are sized.
When a rule is added to the JKRuleView it needs to grow in size. JKRuleView calls descendantFrameChanged: on it's parent view (JKDistributedView) to indicate all children of JKDistributedView need to be resized and repositioned.

So the finder smart folder view would be created using 3 views as subviews in a JKDistributedView. The JKRuleView, the NSOutlineView (using a dynamic vertical resize hint) and a third view at the bottom to display the path of the selected file. JKDistributedView makes sure the JKRuleView and the path view have a fixed size, the NSOutlineView will fill all space in between. Now when you click the add button in the JKRuleView a new rule will be added, JKDistributedView will increase JKRuleViews height and decrease the height of the NSOutlineView

Wednesday, December 13, 2006

Cocoa UI spit & polish

When playing with Interface Builder to create a UI for my application I sometimes run into the problem of trying to recreate a visual element used in Apple software. There are a lot of buttons and gradients used repeatedly in several Apple applications. When adding buttons with similar functionality I try to use the same artwork Apple uses for consistency.

The problem is that most of the buttons for example are custom designed by Apple and are not available by drag-n-drop in Interface builder.

So here is a collection of some images and custom classes that can be used for free in you application to add the spit and polish that makes your application look like a real Apple application. (Be sure to read the licenses for the specifics on copyrights).


An effort to give developers guidelines for replicated Apple interface elements was started under the name IndieHIG:
The IndieHIG Wiki is a place where developers and UI designers can come together to create a new set of Human Interface Guidelines to supplement Apple’s guidelines. Apple has neglected to update their HIG with modern UI designs and controls, so developers have been forced to replicate these UI elements on their own to keep their applications from looking dated. Since each developer has slightly different implementations of these elements, it has resulted in a fairly inconsistent look and feel for Mac OS users.

Maybe it's an idea to provide implementations of interface elements that follow these guidelines? For example the Polished Metal page describes the properties of a currect Polished window, for wich an implementation already exists in the form of TunesWindow.

I'm currently working on an implementation of a RuleEditor as used by the Finder to create smart folders:



When finished I'll document the properties of a rule editor in the IndieHIG and publish the sources of this class.

Sunday, December 10, 2006

XCode todo list

One of the things I use in TextMate regularly is the apple-cmd-b key combo, to bring up a todo list for the current project. Whenever I have something planned in my code, but don't feel like implementing it yet I annotate this piece of code with a comment like:

// TODO: check if url exists before saving it
saveURL(url);
The todo plugin will list all these TODO's from my code which gives me an indication on how to improve my code further.

The problem is that while I use TextMate for my web and java programming, I use XCode for most of the real programming done using Objective-C/Cocoa. But XCode doesn't have the todo feature and there is no way to add plugin's to XCode. Even a google search resulted in nothing on the subject.

So for now I'm using the Lightweight issue tracking bash script I found which seems like the only solution usable in combination with XCode.

# grep for "TODO" string
todo()
{
if [ $# -lt 1 ]; then
grep -R -n "TODO: " . | grep -v ".svn"
else
# loop through the args
while [ -n "$1" ]
do
grep -R -n "TODO: " "$1" | grep -v ".svn"
shift
done
fi
}


Add this script to your ~/.bash_profile to be able to execute the todo command that searches the current directory, or the directories given as argument for // TODO: lines.

Saturday, December 09, 2006

XCode Animations - Core Graphics

XCode Animations - Core Graphics:

Ever wanted to be able to use fancy transitions and animations in your Xcode applications? This tutorial provides the method and the means to implement terrific flips and ripples throughout your app, showing window transition effects using both undocumented and documented Objective-C code that can be implemented anywhere quickly and efficiently.


A small, quickly readable eBook that teaches the use of undocumented Core Graphics functionality. This certainly falls in the category of Undocumented Goodness and usage is therefore discouraged. That being said, if you would like to add effects like the ones used in applications like Quicksilver, Virtue Desktops and certain Apple applications I recommend you read this eBook.

Download (zip | pdf)

Monday, October 30, 2006

Why this weblog?

Welcome to my new weblog. I won't introduce myself again, see my profile for more about me. I will tell you that I've started multiple weblogs before, none of which existed very long, but I intend to change this. So why another weblog and why do I think this one will survive?

I own a Apple Powerbook 12" for over three years now. I've always programmed, mostly using Java. Being interested in programming I had to explore the Java features of XCode. I wasn't that impressed, but I was impressed about what I could do with XCode and Objective-C. I almost instantly liked Objective-C better then Java. This eventually made me signup for an Apple Student Developer membership, with in the back of my mind the possibility to sign up for a WWDC scholarship. I did send in a WWDC scholarship application, not knowing what my chances were, but eventually a WWDC ticket showed up in my ADC library.

So this summer I made my first visit to an Apple WWDC conference!

Inspired by all the things I've seen there, I got back to the Netherlands with renewed energy to start developing new software. I'll try to keep you posted about my adventures on my journey as a cocoa developer as much as possible.

For the one or two readers that are actually reading this weblog, wondering why it's called Cocoa Pirate: I said I will post about my Cocoa adventures (Adventures -> Pirate - Thus Cocoa Pirate, lol)