I was trying to do an instance field of 1 bit in Objective-C, however when I try this @property BYTE Z : 1; I get an error saying Property name cannot be a bitfield.

What Can't I do so? Is there a workaround this error?

Thanks

有帮助吗?

解决方案

The smallest allocable unit of memory is 1 Byte of most machines.There isn't a way to allocate 1 bit, it may be not mappable.It must contain all ASCII characters.
So just use a Byte and then read the bitmask.

Use something like:

@property (nonatomic) Byte byte;

Then use a macro for reading:

#define BitAtIndex(byte,index) (byte & (1<<index))!=0

PS: Of course the index can't be greater than 7.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top