小编use*_*134的帖子

在'id'类型的对象上找不到属性''

Property 'aVariable' not found on object of type id在尝试读取或写入数组的变量时得到了.不应该知道我添加的对象是什么类?还注意到它用于读取值NSLog(@" %@",[[anArray objectAtIndex:0] aVariable]);

我是Objective C的初学者,所以我可能会遇到一些简单的事情.

一个东西

@interface AnObject : NSObject

@property (nonatomic,readwrite) int aVariable;

@end
Run Code Online (Sandbox Code Playgroud)

AnotherObject

@interface AnotherObject : NSObject

@end
Run Code Online (Sandbox Code Playgroud)

test.h

#import "test.h"

@implementation AnObject
@synthesize aVariable;

- (id)init
{
    self = [super init];
    if (self) {
        aVariable=0;
    }
    return self;
}  

@end
Run Code Online (Sandbox Code Playgroud)

test.m

@implementation AnotherObject

- (id)init
{
    self = [super init];
    if (self) { }
    return self;
}  

- (NSMutableArray*) addToArray
{
    NSMutableArray* anArray = …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch properties objective-c

20
推荐指数
2
解决办法
3万
查看次数

标签 统计

cocoa-touch ×1

objective-c ×1

properties ×1