Objective-C:在 iOS 中转发消息
是否可以使用“转发”(http://en.wikipedia.org/wiki /Objective-C#Forwarding)在 iOS 中?
我尝试了此处找到的以下代码:
- (retval_t) forward: (SEL) sel : (arglist_t) args
但我收到一条错误消息:
错误:“retval_t”之前应有“)”
所以我阅读这里并尝试:
- (retval_t)forward:(SEL)sel args:(arglist_t) args
但我收到了同样的错误消息...
我做错了什么?我需要进口一些东西吗?
@bbum:我尝试创建一个线程安全的 NSMutableArray 并想使用我在这里找到的代码: NSMutableDictionary 线程安全
Is it possible to use "Forwarding" (http://en.wikipedia.org/wiki/Objective-C#Forwarding) in iOS?
I tried the following code I found here:
- (retval_t) forward: (SEL) sel : (arglist_t) args
But I get an error message:
error: expected ')' before 'retval_t'
So I read here and try:
- (retval_t)forward:(SEL)sel args:(arglist_t) args
But I got the same error message...
What am I doing wrong? Do I need to import something?
@bbum: I try to create a thread safe NSMutableArray and want to use the code I found here:
NSMutableDictionary thread safety
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。您看到的是 Objective-C 的 GNU 变体,它与 Apple 变体略有不同。
您希望使用
-forwardInvocauation:
而不是-forward::
或-forward:args:
。请参阅 http://developer.apple.com /library/ios/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtForwarding.html 了解有关如何的更多信息使用 iOS 进行操作。Yes. What you're seeing there is the GNU variant of Objective-C, which is slightly different from the Apple variant.
You want to use
-forwardInvocation:
rather than-forward::
or-forward:args:
. See http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtForwarding.html for more info on how to do it with iOS.以下是我用于 iOSforwardInspiration(消息转发)的模式:
需要注意的是,转发的消息的返回值会自动返回到原始发送者。
Here's the pattern I use for iOS forwardInvocation (message forwarding):
It is important to note that the return value of the message that’s forwarded is automatically returned to the original sender.