Reputation: 14408
I m pretty new to objective-c, and trying some examples on my own. Here is my sample code
#import <objc/objc.h>
#import <Foundation/Foundation.h>
@interface Test:NSObject
{
int noOfWheels;
int total;
}
@property int noOfWheels;
@property int total;
-(void) print;
@end
@implementation Test
@synthesize noOfWheels, total;
-(void) print
{
NSLog (@" noofWheels is %i, total %i ", noOfWheels, total);
}
@end
int main ( int argc, char ** argv)
{
Test *t = [Test alloc];
t = [t init];
[t setnoOfWheels: 10];
[t settotal: 300];
[t print];
}
and it compiled with no error, but when i run the program i get the following error.
Uncaught exception NSInvalidArgumentException, reason: -[Test setnoOfWheels:]: unrecognized selector sent to instance 0x87aef48
What am i doing wrong in my code ?
Upvotes: 1
Views: 79
Reputation: 1109
[t setnoOfWheels: 10];
should be
[t setNoOfWheels: 10];
or even better, since you're declaring a property:
t.noOfWheels = 10;
Upvotes: 3
Reputation: 170809
By default 1st letter of iVar is capitalized in setter method name. So correct call will be:
[t setNoOfWheels: 10];
Upvotes: 3