2
我在swift 3.0的swift 2.3中遇到了一个不寻常的问题。有一次,我的代码转换,从2.3到3.0,我得到这个问题:“不明确的参考成员‘下标’,Swift 3.0:对成员'Subscript'问题的模糊引用
代码:
dynamic func onDataNotification(notification: NSNotification) {
var data = notification.userInfo as! Dictionary<NSString, ARoutedMessage>
if let packet = data[AEnginePacketDataKey] as? AEngineMessage,
currentDevice = self.currentDevice() {
if packet.messageId == MessageId.message && currentDevice.isDevice() {
// Some code
}
}
}
开始,让数据包获取错误=数据[AEnginePacketDataKey]作为模糊引用成员'下标',我不明白为什么?其他:
// String
extern NSString *AEnginePacketDataKey;
//ARoutedMessage Class
@interface ARoutedMessage : NSObject
@property NSMutableArray *payloadParameters;
@end
//AEngineMessage Class
@interface AEngineMessage : ARoutedMessage
@property (readonly)MessageId messageId;
- (id) initWithMessageId:(MessageId) mId;
@end
请帮我一把。
如果你假设NSString是一个基于星号的指针......它不是。这就是Objective C对象的声明。一个NSString指针将是“NSString ** foo” –
@LeeAnnRucker经过双重检查,我很确定我的答案是正确的。 Objective C中的对象变量是指向它们对象的指针。 'NSString * foo'是一个指向NSString的指针。 'NSString ** foo'将是一个指向指针的指针。 – Robert