我在理解某事时遇到了一些困难。我的应用程序中有很多属性:
@property (nonatomic, retain) AVAudioPlayer *audioPlayer;
@property (readwrite) NSInteger buttonCount;
@property (nonatomic, retain) NSString *soundSelected;
@property (readwrite) float fadeDecrease;
@property (readwrite) float fadeDelay;
这些显然都是在我的.m文件中合成的。 然而,虽然 audioPlayer 和 soundSelected 在 dealloc 中发布正常,但 int buttonCount 给出了这个警告: “无效的接收者类型‘NSInteger’” 而花车实际上让编译器哭泣: “无法转换为指针类型”
这与它们不是对象类型和/或未保留的事实有关吗? 他们不被释放可以吗?
谢谢。
最佳答案
NSInteger
和 float
一样,不是 Objective-C 类型,也不遵循通常的保留/释放模型。他们只是原始人。为属性分配值就足够了。
@property (readwrite, assign) NSInteger buttonCount;
应有尽有。
NSNumber
但是确实遵循通常的保留/释放周期,因此相应地添加属性。
关于objective-c - Objective-C : Releasing int/float properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5253493/