在Objective-C中创建整数数组 [英] Create an array of integers property in Objective-C
本文介绍了在Objective-C中创建整数数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Objective-C中创建整数数组的属性时遇到麻烦. 我不确定在Obj-C中是否还可以做到这一点,所以我希望有人可以帮助我找出如何正确执行此操作或提供替代解决方案.
I'm having troubles creating a property of an array of integers in Objective-C. I'm not sure whether this is even possible to do in Obj-C so I'm hoping someone can help me in finding out either how to do it correctly or provide an alternative solution.
myclass.h
myclass.h
@interface myClass : NSObject {
@private int doubleDigits[10];
}
@property int doubleDigits;
@end
myclass.m
myclass.m
@implementation myClass
@synthesize doubleDigits;
-(id) init {
self = [super init];
int doubleDigits[10] = {1,2,3,4,5,6,7,8,9,10};
return self;
}
@end
构建并运行时,出现以下错误:
When I build and run, I get the following error:
错误:属性"doubleDigits"的类型 与ivar类型不匹配 'doubleDigits'
error: type of property 'doubleDigits' does not match type of ivar 'doubleDigits'
推荐答案
这应该有效:
@interface MyClass
{
int _doubleDigits[10];
}
@property(readonly) int *doubleDigits;
@end
@implementation MyClass
- (int *)doubleDigits
{
return _doubleDigits;
}
@end
这篇关于在Objective-C中创建整数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文