I have follow Objective-C code. But i am not understanding
what is
alloc
,init
inCar *toyota = [[Car alloc] init];
?from where this method came from?
setModel
// Car.h
#import <Foundation/Foundation.h>
@interface Car : NSObject {
}
@property (copy) NSString *model;
- (void)drive;
@end
// Car.m
#import "Car.h"
@implementation Car {
double _odometer;
}
@synthesize model = _model;
- (void)drive {
NSLog(@"Driving a %@. Vrooooom!", self.model);
}
@end
// main.m
#import <Foundation/Foundation.h>
#import "Car.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Car *toyota = [[Car alloc] init];
[toyota setModel:@"Toyota Corolla"];
NSLog(@"Created a %@", [toyota model]); // SQL: Insert into Car value
toyota.model = @"Toyota Camry"; // SQL: Update car set model=''
NSLog(@"Changed the car to a %@", toyota.model);
[toyota drive]; // SQL: Select *from Car
}
return 0;
}