Trying to do something really simple, but can’t figure out the syntax.
I have a class called Word.h which has 8 properties, strings and integers. For the sake of keeping things simple, I’ll stick to 2 here:
#import <UIKit/UIKit.h>
@interface Word : NSObject
@property (nonatomic, strong) NSString *word;
@property (nonatomic, strong) NSNumber *wordLevel;
@end
Both properties are synthesised in the .m file
I then want to create some objects in another file (UIViewController). In the .h file I have this:
#import "Word.h"
and in the .m file, this:
Word *newWord = [[Word alloc] init];
[newWord setWord:@"theorise"];
[newWord setWordLevel:6];
Word *newWord1 = [[Word alloc] init];
[newWord setWord:@"implicit"];
[newWord setWordLevel:7];
Word *newWord2 = [[Word alloc] init];
[newWord setWord:@"incredible"];
[newWord setWordLevel:9];
I now get an error message “Implicit conversion of ‘int’ to ‘NSNumber *’ is disallowed with ARC”
What am I doing wrong…is the property defined incorrectly in the class file?? How do I access this property. It works fine with the string.
I will also want to access the properties later – how do I do that…for example:
cell.label1.text = [newWord2 wordLevel];
Is this the right syntax???
Hoping someone can help me, tearing clumps of hair out here!
M
You declared
wordLevelto be anNSNumber, an object. You are treating it in your code like it is a plain Cint. You have to decide which your want it to be and treat it that way consistently. For example, for a plain Cintproperty you would instead declare:On the other hand if you really want
wordLevelto be anNSNumberyou need to use the setter like this: