目标 C:释放 int/float 属性

发布于 2024-10-20 21:24:23 字数 504 浏览 6 评论 0原文

我在理解某些事情时遇到了一些困难。我的应用程序中有很多属性:

@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’无效” 浮点数实际上让编译器哭泣: “无法转换为指针类型”

这与它们不是对象类型和/或未保留这一事实有关吗? 他们不被释放可以吗?

谢谢。

I'm having some trouble understanding something. I got a bunch of propeties in my app:

@property (nonatomic, retain) AVAudioPlayer *audioPlayer;
@property (readwrite) NSInteger buttonCount;
@property (nonatomic, retain) NSString *soundSelected;
@property (readwrite) float fadeDecrease;
@property (readwrite) float fadeDelay;

These are obviously all synthesized in my .m file.
However, while audioPlayer and soundSelected are released fine in dealloc, the int buttonCount gives this warning:
"Invalid receiver type 'NSInteger'"
and the floats actually make the compiler cry with:
"Cannot convert to a pointer type"

Has this got something to do with the fact that they are not of object types and/or not retained?
Is it OK that they are not released?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枯寂 2024-10-27 21:24:23

NSIntegerfloat 一样,不是 Objective-C 类型,也不遵循通常的保留/释放模型。他们只是原始人。为属性赋值就足够了。

@property (readwrite, assign) NSInteger buttonCount;

应该就是你所需要的。

然而,NSNumber 确实遵循通常的保留/释放周期,因此请相应地添加属性。

NSInteger, like float, are not Objective-C types and do not follow the usual retain/release model. They're just primitives. Assigning values to the property will be sufficient.

@property (readwrite, assign) NSInteger buttonCount;

should be all you need.

NSNumber however does follow the usual retain/release cycle, so add attributes accordingly.

寻找一个思念的角度 2024-10-27 21:24:23

这和这个有关系吗?
事实上它们不是对象类型
和/或不保留?他们不被释放可以吗?

是的。您只能释放具有保留计数的对象。像 int、float 和 NSInteger 这样的原始数据类型不需要保留/释放,因为它们不是引用内存其他部分的指针。

如果您想了解有关内存管理的更多信息,请尝试查看此文档页面:

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html%23// apple_ref/doc/uid/10000011-SW1

Has this got something to do with the
fact that they are not of object types
and/or not retained? Is it OK that they are not released?

Yes. You can only release objects that have a retain count. Primitive datatypes like int, float, and NSInteger do not need to be retained/released because they are not pointers referring to other parts of memory.

If you want to learn more about memory management, try taking a look at this documentation page:

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html%23//apple_ref/doc/uid/10000011-SW1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文