No quiz today, but there will be one on Thursday
Homework 5 asks about your progress reports etc.
obj.method(arg1, arg2)
[obj method: arg1 param2: arg2]
[obj method: arg]
part is just another syntax for obj.method(arg)
param2:
part is a Smalltalk idiosyncracy, somewhat but not quite like “named parameters” in languages such as C#, Groovy, or Scala[myArray insertObject: obj atIndex: 1]
, calls method insertObject:atIndex:
@interface classname : superclassname { // instance variables } + (return_type)classMethod:(param1_type)param1_varName; - (return_type)instanceMethod:(param1_type)param1_varName :(param2_type)param2_varName; @end
@implementation classname + (return_type)classMethod { // implementation } - (return_type)instanceMethod { // implementation } @end
alloc
and init
methods to an object: [[NSDate alloc] init]
get
: name/setName
@property (nonatomic, retain) NSString *name;
nonatomic
and retain
for now.@property
declaration goes in the .h file@synthesize name;
q.name
nil
is a null reference@"Hello"
self
is like this
in JavaNSString
, NSArray
, NSMutableArray
, NSMutableDictionary
NSString *greeting = @"Hello";
id
is a generic object reference that doesn't require an asterisk: id greeting = ...;
IBOutlet
: Object linked to .xib file entity
@property (nonatomic, retain) IBOutlet UITextView *choice_text;
IBAction
: Method that can be called from UI@property (nonatomic, retain) NSArray *choices;
@synthesize choices;after
@implementation
viewDidLoad
, add the following code after [super viewDidLoad];
:
self.choices = [NSArray arrayWithObjects: @"Android", @"Blackberry", @"iOS", @"Windows Mobile"];
viewDidReceiveMemoryWarning
, add
self.choices = nil;This helps with the semi-automatic memory management.
@property (nonatomic, retain) IBOutlet UILabel *choice_text; -(IBAction)choice_btn_touch:(id)sender;
choice_text
is a property, so what do you need to do in ViewController.m?ViewDidReceiveMemoryWarning
?@end
in the .m file:
-(IBAction)choice_btn_touch:(id)sender { int count = [self.choices count]; int index = arc4random() % count; NSString *choice = [self.choices objectAtIndex:index]; self.choice_text.text = choice; }
choice_text
property.