是否可以在 iOS 中使用“转发”(http://en.wikipedia.org/wiki/Objective-C#Forwarding)?
我尝试了以下我发现的代码 here :
- (retval_t) forward: (SEL) sel : (arglist_t) args
但是我收到一条错误消息:
error: expected ')' before 'retval_t'
所以我读了here并尝试:
- (retval_t)forward:(SEL)sel args:(arglist_t) args
但是我得到了同样的错误信息...
我做错了什么?我需要导入什么吗?
@bbum:我尝试创建一个线程安全的 NSMutableArray 并想使用我在这里找到的代码: NSMutableDictionary thread safety
最佳答案
是的。您在这里看到的是 Objective-C 的 GNU 变体,它与 Apple 变体略有不同。
您想使用 -forwardInvocation:
而不是 -forward::
或 -forward:args:
。参见 http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtForwarding.html有关如何使用 iOS 执行此操作的更多信息。
关于iphone - Objective-C:在 iOS 中转发消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6986170/