Sunday, July 12, 2009

iPhone App: Amazing Polygon App - update 1 Slider

Added a slider to facilitate incrementing/decrementing the number of sides in the polygon.



General Process:

  • Create the action method in your Controller to process events from the slider.
  • Add an Outlet to your Controller header file IBOutlet UISlider *slider;.
  • Mark this method with the (IBAction) macro.
  • Bring up your .xib in Interface Builder
  • Add a slider control (UISlider) to the View
  • Make a connection from the slider control to the Controller object...when you release it you will be prompted to select the action to be invoked.
  • Save everything and test it out.

Simple!

Cocoa App Pieces

A Cocoa application is made up of several pieces:

  • Compiled code (written code compiled + framework code/libraries)
  • Interface Files (UI Elements/Controls, Outlets, Connections, etc.)
  • Resources (sounds, text/strings, audio, etc)
  • Application Configuration (Info.plist)

Cocoa Looping a Dictionary

From the stanford course

NSMutableDictionary *dict = [NSMutableDictionary dictionary];

[dict setValue:[NSDate date] forKey:@"now"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:-60] forKey:@"1 minutes ago"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:60 * 30] forKey:@"30 minutes from now"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:-60 * 60 * 24] forKey:@"24 hours ago"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:-7 * 60 * 60 * 24] forKey:@"a week ago today"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:365 * 60 * 60 * 24] forKey:@"a year from now"];


for (NSString *key in dict)

{

NSDate *date = [dict objectForKey:key];

NSLog([NSString stringWithFormat:@"Key: '%@' Date: '%@'", key, date]);

}



Cocoa URL's using NSUrl

#import


NSURL *someURL = [NSURL URLWithString:@"http://www.somesite.com:8080/path/targetpage.html"];

NSLog([NSString stringWithFormat:@"Host: '%@' Port: '%d'", [someURL host], [someURL port]]);


Host: www.somesite.com
Port: 8080

Objective-C Training





Cocoa Dictionary like Java HashMap

COCOA has a couple dictionary objects. One is changeable (mutable) and one is not.

NSDictionary and NSMutableDictionary


NSMutableDictionary *dict = [NSMutableDictionary dictionary];

[dict setValue:[NSDate date] forKey:@"now"];

[dict setValue:[NSDate dateWithTimeIntervalSinceNow:-60] forKey:@"1 minutes ago"];


Debugging session completed

Just completed the debugging session from the Stanford course. Helpful.