Swayer Geroge
Swayer Geroge

Reputation: 103

Swift 3.0 : Ambiguous reference to member 'Subscript' issue

I have got an unusual problem in swift 2.3 to Swift 3.0. Once I convert the code from 2.3 to 3.0, i am getting this issue:'Ambiguous reference to member 'Subscript',

Code are :

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 
            }
        }
    } 

Getting error on let packet = data[AEnginePacketDataKey] as Ambiguous reference to member 'Subscript', I don't understand why?. Other:

// 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

Please help me out.

Upvotes: 2

Views: 2090

Answers (1)

Robert
Robert

Reputation: 6810

The "ambiguous reference" error is telling you that the variable you're trying to use as a subscript is the wrong type.

In this case data is a dictionary that is expecting an NSString subscript. It looks like AEnginePacketDataKey is defined as a pointer to an NSString in your Objective C code, but you don't show where (if) anything is assigned to it. Make sure you assign an actual NSString to it before you try to use it as a subscript of data.

Upvotes: 2

Related Questions