这个问题涉及到与移动基板挂钩,但只要你知道Objective-C,你可能会提供帮助。没有显式声明,为属性ivars生成什么名字?
我有这个课程,我从UIKit倾销。这里是一块吧:
@interface UIStatusBarItem : NSObject {
int _type;
}
@property(nonatomic, readonly, retain) int type;
@property(nonatomic, readonly, retain) int leftOrder;
@property(nonatomic, readonly, retain) int rightOrder;
@property(nonatomic, readonly, retain) int priority;
...
@end
当然,如果我想设置int type
,例如,16,我会做:
MSHookIvar<int>(self, "_type") = 16;
从此,[self type]
将返回16.这我知道的很多。
我的问题是,我不知道是什么编译器“名”的int
其中对于价值int leftOrder
,int rightOrder
和int priority
存储。我尝试过:
MSHookIvar<int>(self, "leftOrder")
但这不正确,并导致手机崩溃。我真的需要知道的是,如果你没有自己指定这些变量是如何自动命名的。谢谢
此外,我讨厌听起来像刺,但请不要只是回答“不要这样做,这是不安全的。”我知道这不是,这就是为什么我的大部分产品都在Cydia而不是App Store = P
我的猜测是,一个是以下划线_xxxx开头的。但是您需要将它们添加到下面的实现中。 _类型。我知道的一件事是,你不需要属性中的retain关键字作为int值,因为它们不是nsobjects。 – peterept 2012-02-03 13:37:02