2011-01-27 84 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