Archive for the ‘Mondo Kode’ Category

Zathras.framework

Sunday, January 24th, 2010

Recently I started using some kode (UKKQueue) that Uli Kusterer published as open source. Instead of just including the source files in my software I decided to wrap it in a framework.

One of the advantages of taking someone else’s kode and wrapping it in a framework in this manner is that it makes you stop and take the time to examine the kode. It’s great that you have kode that you didnt’ write and you haven’t succumbed to the “not invented here” phenomena, but you’re still using this kode in your application. You need to do your homework and examine what it is your plugging into.

Uli’s kode is solid and many people have already hammered at it. But sometimes it’s good to make trivial changes to get that feeling of ownership. For instance: Some people like the { on the line after the function implementation, and some people like the { an the same line as the function implementation. This is a trivial coding style difference; but if while you are reading the source kode you change it to your preferred style you will gain a sense of ownership. Or maybe this isn’t true at all and I’m trying to justify the fact that I do this when reading kode that I’m including in my project.

Here is a more concrete example of something I changed. In the file UKFileWatcher.h Uli uses a category to define the protocol UKFileWatcherDelegate. There is nothing wrong with this. In fact, it is the standard by which Objective-C libraries are written. This is the way Apple defines delegate protocols in their API.

@protocol UKFileWatcher
 
// +(id) sharedFileWatcher;			// Singleton accessor. Not officially part of the protocol, but use this name if you provide a singleton.
 
-(void) addPath: (NSString*)path;
-(void) removePath: (NSString*)path;
 
-(id)   delegate;
-(void) setDelegate: (id)newDelegate;
 
@end
 
// -----------------------------------------------------------------------------
//  Methods delegates need to provide:
// -----------------------------------------------------------------------------
 
@interface NSObject (UKFileWatcherDelegate)
 
-(void) watcher: (id<UKFileWatcher>)kq receivedNotification: (NSString*)nm forPath: (NSString*)fpath;
 
@end

Personally, I prefer formal protocols So I changed the kode to use a formal protocol. At the end of the day, the code is functionally equivalent, but I twiddled with the knobs while I read the kode.

@protocol UKFileWatcher
 
-(void) addPath: (NSString*)path;
-(void) removePath: (NSString*)path;
 
-(id)   delegate;
-(void) setDelegate: (id<UKFileWatcherDelegate>)newDelegate;
 
@end
 
// -----------------------------------------------------------------------------
//  Methods delegates need to provide:
// -----------------------------------------------------------------------------
@protocol UKFileWatcherDelegate
-(void) watcher: (id<UKFileWatcher>)kq receivedNotification: (NSString*)nm forPath: (NSString*)fpath;
@end

So I’ve created Zathras.framework. In the future, I plan to wrap any other kode by Uli that I use into this framework.

Kode on.

CocoaMondo Kit 1.1

Monday, December 28th, 2009

I looked high and low for a switch interface similar to the Time Machine switch. The iPhone uses this style of interface all the time with the UISwitch. Since I couldn’t find an implementation, I bit the bullet, created one and added it to CocoaMondo Kit 1.1.

Please don’t abuse this control and replace all your checkboxes with switches. Use common sense. A good guildine is to use a switch for a desktop application when the state of the switch has fare reaching implications. For example: The switch disables or enables the core functionality of the application.



Cocoa Mondo Kit 1.1

If switches are used sparingly then the user will hopefully pay closer attention when enabling or disabling them.

Kode on!

Cocoa Mondo Kit 1.0

Sunday, December 6th, 2009

A year ago I released the MondoTextField. Well I’ve modified the component, made some bug fixes, and wrapped it in an Interface Builder plugin called Cocoa Mondo Kit.



Cocoa Mondo Kit 1.0

It’s seems slightly silly to release an Interface Builder plugin with only one component, but including the component as a framework is much cleaner than importing a bunch of source files.

Kode on!

UI Blunder

Monday, November 30th, 2009

What’s wrong with this picture?

UIBlunder

  1. Files Ready to be Written to the Disc
  2. The headers “Name”, “Size”,…,”Location”

On the first point, I’ve inserted a read only DVD into my machine and am shown a “Files Ready to be Written to Disc” section. How is this helpful and not confusing to regular users? Why do I care that Windows really wanted to write a file to the DVD but can’t because it’s read only?

The second point is more subtle. The column headers don’t even apply to this icon mode. You can’t resize them in this view. They are there in case you decide to switch to a view mode that might need them. Again, how is this helpful and not confusing to regular users?

The screenshot is from Vista.

Kode on!

Switch between .m and .h file in VI

Tuesday, November 24th, 2009

If you are working on Objective-C kode in VI the following functions and key mapping will allow you to quickly switch between the header and implementation file.

" Switch editing between
" *.c and *.h files  (C)
" or
" *.m and *.h files  (ObjC)
function! Flip_Extension()
 
  if match(expand("%"),'\.m') > 0
    let s:flipname = substitute(expand("%"),'\.m\(.*\)','.h\1',"")
    call LoadFile(s:flipname)
  elseif match(expand("%"),"\\.h") > 0
    let s:flipname = substitute(expand("%"),'\.h\(.*\)','.m\1',"")
    if (filereadable(s:flipname)) > 0
      call LoadFile(s:flipname)
    else
      let s:flipname = substitute(expand("%"),'\.h\(.*\)','.c\1',"")
      call LoadFile(s:flipname)
    endif
  elseif match(expand("%"),"\\.c") > 0
    let s:flipname = substitute(expand("%"),'\.c\(.*\)','.h\1',"")
    call LoadFile(s:flipname)
  endif
 
endfun
 
" Find the filename in an existing buffer
" if it exists open that buffer so you don't
" lose your file position.
function! LoadFile(filename)
  let s:bufname = bufname(a:filename)
  if (strlen(s:bufname)) > 0
    exe ":buffer" s:bufname
  else
    exe ":find " a:filename
  endif
endfun
 
map <F4> :call Flip_Extension()<CR>

Kode on!

Reference:
Easily switch between source and header file