December 14
A quick blog post of how to implement a variable argument input into a method. Let say we have a method that takes variable length input: [self sortItems:item1,item2,item3,nil]; Then the implementation looks like -(void)sortItems:(id) firstObject, … { id eachObject; va_list argsList; if (firstObject) { // Do something to the first object // Now loop over the rest of the items va_start(argsList, firstObject); while(eachObject=va_arg(argsList, id)) { // Do something to this object } va_end(argsList); } } You see and use methods alot but always good to know how to implement them properly. This was taken from the Apple sample code: http://developer.apple.com/library/mac/#qa/qa2005/qa1405.html
Posted by Jeff . Filed under Objective-C, Sample Code |
August 17
A recent problem that i came across was the issue with delegation and subclassing. I was trying to subclass a class and also perform delegation with the subclass, ignoring the parents delegate methods. It’s not a strange thing to do, but was a little tricky to get it working in my project. Here’s a simplified example of how i did it: I created Class1 which is our parent class. The header file includes the declaration of the delegation protocol: @protocol Class1Delegate @required -(void)method1; @optional -(void)optionalMethod1; @end @interface Class1 : NSObject { // The delegate id delegate; } @property (nonatomic, assign) [...]
Posted by Jeff . Filed under Objective-C, Tutorials |
April 11
Xcode is the IDE used for iPhone development. I think its great, i guess i’ve been using it for so long! Here are my 10 top tips for increasing your Xcode development: Quick Comment You can quickly comment out chunks of code with the following: Select some lines of code. Command-/ Quick .h / .m File Switch You can quickly switch between the header(.h) and implementation(.m) files with the following: Command-Option Up-Arrow Add a Bookmark Adding a bookmark is really useful for switching between classes. It makes developing alot easier so i would recommend to start using them. Add a [...]
Posted by Jeff . Filed under Objective-C, XCode |
March 11
Was told about this really useful script that converts NIB files to Objective-C Code, check it out: http://github.com/akosma/nib2objc Is useful to see exactly how different elements can be created using code.
Posted by Jeff . Filed under Objective-C |
October 13
Hello internet world. I’m just posting some code here to creating a basic animation timer in objective-c. Quite handy for quickly creating animations that use Core Animation libraries. The code to start the timer is: [NSTimer scheduledTimerWithTimeInterval: 3.0 target: self selector : @selector(handleTimer:) userInfo: nil repeats: YES]; and that calls the handleTimer method: – (void)handleTimer:(NSTimer*)timer { CATransition *applicationLoadViewIn = [CATransition animation]; [applicationLoadViewIn setDuration:1]; [applicationLoadViewIn setType:kCATransitionReveal]; [applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]]; [[starImageView1 layer] addAnimation:applicationLoadViewIn forKey:kCATransitionReveal]; [UIView commitAnimations]; } This simply moves a UIImageView that i’ve already added to the scene in a reveal transition. I’d love to add a screen grab but want to [...]
Posted by Jeff . Filed under Core Animation, NSTimer, Objective-C |