I have an a property declared in .h
as
我有一个在.h中声明的属性
@property (nonatomic, assign) int timeSig_Numerator;
and an instance variable declared in the .h
as
和.h中声明的实例变量
int mTimeSig_Numerator;
in the .m
I synthesize with
在我合成的.m中
@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?
我在合成之前声明了一个C函数,需要使用mTimeSig_Numerator。什么是使实例变量对我的C函数可见而不将其作为函数参数传递的最佳方法?
1 个解决方案
#1
4
Since mTimeSig_Numerator
is an instance variable, each instance of your class has its own mTimeSig_Numerator
. As a C function is decoupled from any given class/class instance, how would it know from which instance it should obtain mTimeSig_Numerator
?
由于mTimeSig_Numerator是一个实例变量,因此您的类的每个实例都有自己的mTimeSig_Numerator。由于C函数与任何给定的类/类实例分离,它如何知道它应从哪个实例获取mTimeSig_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.
您的C函数需要一个包含特定实例中mTimeSig_Numerator值的参数,或者一个指向实例本身的参数,或者一些其他机制来告诉函数它应该使用哪个特定的实例/实例变量。
#1
4
Since mTimeSig_Numerator
is an instance variable, each instance of your class has its own mTimeSig_Numerator
. As a C function is decoupled from any given class/class instance, how would it know from which instance it should obtain mTimeSig_Numerator
?
由于mTimeSig_Numerator是一个实例变量,因此您的类的每个实例都有自己的mTimeSig_Numerator。由于C函数与任何给定的类/类实例分离,它如何知道它应从哪个实例获取mTimeSig_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.
您的C函数需要一个包含特定实例中mTimeSig_Numerator值的参数,或者一个指向实例本身的参数,或者一些其他机制来告诉函数它应该使用哪个特定的实例/实例变量。