Compiler error "setter method" for using dot syntax - setter specified

I cannot understand why my getter and setter code is not working. In some code example, I went over:

- (NSArray *)sushiTypes { return _sushiRolls; } - (void)setSushiTypes:(NSArray *)sushiRolls { [sushiRolls retain]; [_sushiRolls release]; _sushiRolls = sushiRolls; } 

Then in:

 - (void)viewDidLoad { [super viewDidLoad]; self.sushiTypes = [[NSArray alloc]initWithObjects:@"...]autorelease]; } 

All this time worked, but the sushiTypes property sushiTypes never been declared. I (kind of) get how it works, as it works the same way as a setter / getter, regardless of whether it was synthesized or not.

But here is my code, and I get a compiler error with a property request. Did I miss something?

 #import <Foundation/Foundation.h> @interface Temp0 : NSObject { NSNumber *x1; } -(NSNumber *)x1; -(void)setx1:(NSNumber *)x; @end 

 // #import "Temp0.h" @implementation Temp0 -(NSNumber *)x1 { return x1; } -(void)setx1:(NSNumber *)x { [x retain]; [x1 release]; x1 = x; } -(id)init { self.x1 = [[NSNumber alloc]initWithInt:1]; // Error on this line: // Setter method is needed to assign to object using property assignment syntax [super init]; } @end 

Screenshot of this code and error in Xcode

+4
source share
1 answer

Standard for the capital letter of the first letter of the property in the setter method name. As you pointed out correctly:

 -(void)setSushiTypes:(NSArray *)sushiRolls 

So setX1: is the expected signature of the method.

 -(void)setX1:(NSNumber *)x1; 
+4
source

Source: https://habr.com/ru/post/1396556/


All Articles