Trying to implement an object class within the same file (as you have to) and come across an error when reading the property. Should be simple:
Note - this works fine in Xcode on my computer.
(Edit: because I’m new I have to change the @ signs to @. because I can’t mention more than 2 users in a post)
@.interface Entity: NSObject
@.property (nonatomic) NSString *name;
@.end
@.implementation Entity
@.endint main(int argc, const char * argv[]) {
int playerId; // your id (0 to 4)
scanf("%d", &playerId); fgetc(stdin);// game loop while (1) { Entity *entity = [[Entity alloc] init]; entity.name = @."test"; //this causes an execption }
}
Produces an error:
Uncaught exception NSInvalidArgumentException, reason: Entity(instance) does not recognize setName:
This indicates for some reason you can’t assign properties by either object.property = foo or [object setProperty:foo]. Why not?
If I add the method setName: myself (I shouldn’t have to) E.g:
@.interface Entity: NSObject
@.property (nonatomic) NSString *name;
- (void)setName:(NSString **)name; //have to do double asterisk to escape formatting italic
@.end
@.implementation Entity
- (void)setName:(NSString *)name {
self.name = name;
}
@.end
it’s another error:
Uncaught exception NSInvalidArgumentException, reason: Entity(instance) does not recognize name
It’s like it can’t see the property, anyone have any idea how to fix? Thanks for helping.