iPhone : 基元 getter 和 setter
我现在感觉有点恼火,我做了一些使用浮点数和整数等的 iPhone 项目,一切都很好。
我现在使用 OpenGL 和 GLFloat[] C 数组等,似乎除非我制定方法来设置/获取它们,否则它会在设备(而不是模拟器)上崩溃。现在,由于这些没有设置为属性(我认为 c 数组不能),所以这是有道理的。然而,在没有他们的情况下,该项目已经运行了几个月。代码中的某些内容似乎正在清除任何浮点/整数,以至于调试器可以看到分配的值,但访问它会使手机崩溃。
一旦我认为我对这个平台有所了解,我的想法就会改变,哈哈。
问题是。
如何正确声明和使用浮点数组(float[3])和整数(我通常将它们作为属性)以便您可以设置和获取它们。 您是否需要创建自己的方法来获取和设置它们?
I feel a bit miffed at the moment, I done a few iPhone projects that use floats and ints etc and all is fine.
I now using OpenGL and GLFloat[] C arrays etc and it seems unless I make methods to set / get them it crashes on the device (not the simulator). Now as these are not setup as properties (I don't think c arrays can) it kind of makes sense. However the project has been working for months without them. It seems something in the code is wiping out anything float / ints to the point that the debugger can see an assigned value but accessing it crashes the phone.
As soon as I think I know something for this platform, something changes my mind lol.
The question is.
How do you properly declare and use float arrays (float[3]) and ints (I usually do these as properties) so that you can set and get them.
Should you need to make your own methods to get and set them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
属性的工作方式与基元作为对象的工作方式相同,只是它们被分配而不是保留:
抱歉,有点仓促了。属性不支持C 数组。您必须为 C 数组推出自己的 getter/setter。如果您仍然想拥有属性,可以使用 GLfloat 基元的 NSArray。
Properties work the same way with primatives as Objects, except they get
assign
ed instead ofretain
ed:Sorry, got a little hasty there. C arrays are not supported with properties. You will have to roll your own getter/setter for C arrays. If you still want to have a property, you can use an NSArray of
GLfloat
primatives.