C 函数和对 Objective-C 实例变量的访问
我有一个在 .h
中声明的属性
@property (nonatomic, assign) int timeSig_Numerator;
,以及在 .h
中声明的实例变量,如
int mTimeSig_Numerator;
.m
我合成
@synthesize timeSig_Numerator = mTimeSig_Numerator;
的在综合之前声明的 C 函数,需要使用 mTimeSig_Numerator。使实例变量对我的 C 函数可见而不将其作为函数参数传递的最佳方法是什么?
I have an a property declared in .h
as
@property (nonatomic, assign) int timeSig_Numerator;
and an instance variable declared in the .h
as
int mTimeSig_Numerator;
in the .m
I synthesize with
@synthesize timeSig_Numerator = mTimeSig_Numerator;
I have a C function declared before the synthesize and need to use mTimeSig_Numerator. what is the best way to make the instance variable visible to my C function without passing it in as a function argument?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
mTimeSig_Numerator
是一个实例变量,因此类的每个实例都有自己的mTimeSig_Numerator
。由于 C 函数与任何给定的类/类实例解耦,它如何知道应该从哪个实例获取mTimeSig_Numerator
?您的 C 函数需要一个包含特定实例中的
mTimeSig_Numerator
值的参数,或者一个指向实例本身的参数,或者一些其他机制来告诉函数应该使用哪个特定实例/实例变量。Since
mTimeSig_Numerator
is an instance variable, each instance of your class has its ownmTimeSig_Numerator
. As a C function is decoupled from any given class/class instance, how would it know from which instance it should obtainmTimeSig_Numerator
?Your C function needs either an argument containing the value of
mTimeSig_Numerator
in a specific instance, or an argument pointing to the instance itself, or some other mechanism that tells the function which specific instance/instance variable it should use.