iPhone SDK合成BOOL数组 [英] iPhone SDK synthesizing BOOL Array

查看:138
本文介绍了iPhone SDK合成BOOL数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试合成一个布尔数组这样当编译器错误:

I get a compiler error when trying to synthesize a bool array like this:

// .h

#import <UIKit/UIKit.h>


@interface SomeViewController : UIViewController {

    BOOL boolArray[100];
}

@property (nonatomic) BOOL boolArray;

@end


//m

#import "SomeViewController"


@implementation SomeViewController

@synthesize boolArray;

@end

我大概做了一个根本性的错误,但我能找到它,现在,与boolArray [100]合成也不能工作。

I probably did a fundamental mistake, but I can find it right now, synthesizing with boolArray[100] didn't work either.

推荐答案

您可能需要完整的类型,即
@属性(非原子)BOOL boolArray [100]

You probably need the full type, i.e. @property (nonatomic) BOOL boolArray [100];

[100]是显著类型的信息,而不只是有多少空间可以分配给的指示。

The [100] is significant type information, not just an indication of how much space to allocate.

另外,我觉得酒店将像常量BOOL * 不能分配进行处理,所以它很可能必须只读。做正确的事情可能是让这个只读,这意味着变薄将获取数组指针下标,然后给它分配给数组的成员。

Also, I think the property will be treated like a const BOOL * that can't be assigned, so it would probably have to be readonly. The correct thing to do is probably make this readonly, which means that thins will fetch the array pointer then subscript it to assign to members of the array.

另外,你可以使用的NSArray 这一点,但会要求您使用的NSNumber s的boolVaules这更多的是biotch来处理。

Alternately you can use an NSArray for this, but that will require that you use NSNumbers with boolVaules which is more of a biotch to deal with.

更新

其实愚蠢的编译器不喜欢[]出于某种原因。试试这个:

Actually the stupid compiler doesn't like the [] for some reason. Try this:

@interface TestClass : NSObject {

    const BOOL *boolArray;
}

@property (nonatomic, readonly) const BOOL *boolArray;

@end


@implementation TestClass;

- (const BOOL *)boolArray {
    if (!boolArray)
        boolArray = malloc(sizeof(BOOL) * 100);
    return boolArray;
}

- (void)dealloc {
    [super dealloc];
    free((void *)boolArray);
}

@end

另一个更新

这编译:

@interface TestClass : NSObject {

    BOOL boolArray[100];
}

@property (nonatomic, readonly) const BOOL *boolArray;

@end


@implementation TestClass;

- (const BOOL *)boolArray {
    return boolArray;
}

@end

这是一个奇怪的问题。我希望编译器能解释到底是什么的不满像什么不能用数组类型财产申报。

This is a bizarre issue. I wish the compiler would explain exactly what it's unhappy about like "Can't declare property with array type" or something.

另一个更新

请参阅这个问题:<一href=\"http://stackoverflow.com/questions/476843/create-an-array-of-integers-property-in-objective-c\">http://stackoverflow.com/questions/476843/create-an-array-of-integers-property-in-objective-c

显然是依照C规格,数组是不是一个普通旧数据类型和Objective-C的规范只允许您为POD类型声明属性。据说,这是豆荚definiition:

Apparently according to the C spec, an array is not a "Plain Old Data" type and the Objective-C spec only lets you declare properties for POD types. Supposedly this is the definiition of PODs:

HTTP://www.fnal。 GOV /文档/工作团/ fpcltf /包装/ ISOcxx / DOC / POD.html

但看完这看上去好像荚果的数组是一个POD。所以,我不明白这一点。

But reading that it seems like an array of PODs is a POD. So I don't get it.

这篇关于iPhone SDK合成BOOL数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆