2011-01-27 72 views
0

所以我有一個NSInteger類,現在我想返回NSInteger值。出於某種原因,代碼不起作用。我已經爲NSInteger類聲明瞭@property。NSInteger無法正常工作

@property (readwrite, assign, nonatomic) NSInteger numberFun; 
- (NSInteger)sampleMethod { 
    ... 
    return sample.numberFun; 
} 

編譯器提示「無指針返回指針」。我敢肯定,這意味着我正在使用C類型的Objective-C方法。我想知道這方面的工作。 (儘管我不希望它將一個流行的NSInteger作爲NSNumber返回)。

謝謝

+0

你@synthesize numberFun? – kevboh 2011-01-27 15:53:22

回答

0

以下代碼示例編譯得很好。我建議你提出一個更完整的問題例子,以便我們弄清楚你做錯了什麼。

@interface MyObject : NSObject 
{ } 
@property (readwrite, assign, nonatomic) NSInteger numberFun; 
@end 


@implementation MyObject 
@synthesize numberFun; 
@end 


@interface MyObject2 : NSObject 
{ } 
@property (nonatomic, copy) MyObject* sample; 
@end 


@implementation MyObject2 
@synthesize sample; 
- (NSInteger)sampleMethod { return sample.numberFun; } 
@end 
+0

`@property(nonatomic,copy)MyObject * sample;`很混亂。我建議刪除`MyObject2`,並簡單地顯示一個`main()`分配一個`MyObject`並獲取/設置`numberFun`。 (除此之外的好答案) – bbum 2011-01-27 16:07:33