我有一个方法 AudioServicesCreateSystemSoundID,根据文档,该方法似乎需要传入内存地址(*outSystemSoundID)。
来自 Apple 的网站...
OSStatus AudioServicesCreateSystemSoundID (
CFURLRef inFileURL,
SystemSoundID *outSystemSoundID
);
当我在方法中创建本地对象时,我有这段代码可以工作。该对象已正确分配到内存位置。
这将返回 myTest ,代码为:0(这就是我想要的)
SystemSoundID thisSoundID;
SystemSoundID myTest = AudioServicesCreateSystemSoundID
(
(__bridge CFURLRef)(url), &thisSoundID
);
但这就是我想要做的。 (我已将 self.theSound 设置为 SystemSoundID 属性)。
这将返回 myTest 并带有错误代码:4294967246(我不想要这个)
SystemSoundID myTest = AudioServicesCreateSystemSoundID
(
(__bridge CFURLRef)(url), self.theSound
);
最佳答案
编译器将 self.theSound
翻译为
[self theSound]
其中 -(SystemSoundID)theSound
是(自动合成的)getter 方法
您的属性(默认情况下)从 _theSound
实例获取值
变量。
所以你不能将“属性的地址”传递给函数。 您可以改为传递实例变量的地址:
SystemSoundID myTest = AudioServicesCreateSystemSoundID
(
(__bridge CFURLRef)(url), &self->_theSound
);
绕过属性访问器。但我建议使用临时的 变量代替:
SystemSoundID thisSoundID;
SystemSoundID myTest = AudioServicesCreateSystemSoundID
(
(__bridge CFURLRef)(url), &thisSoundID
);
self.theSound = thisSoundID;
关于ios - AudioServicesCreateSystemSoundID 和内存地址参数 - 如何传递属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21388175/