Xcode 6.3.2: Swift class can't have 2 subscripts methods when it inherits from NSObject

Originator:konstantin.koval1
Number:rdar://21519137 Date Originated:24-Jun-2015 08:14 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.3.2 (6D2105)
Classification:Other Bug Reproducible:Always
 
Summary:
A swift class that inherits from NSObject and has 2 subscript methods has a conflict with a Objective-C.

“Subscript getter with Objective-C selector 'objectForKeyedSubscript:' conflicts with previous declaration with the same Objective-C selector”

Steps to Reproduce:
1 - Create a class 

class A  {
  var a: Int = 10
  
  subscript(key: String) -> Int {
   return a
  }
  
  subscript(key: String) -> String {
    return "\(a)"
  }
}

var b = A()
var res: Int = b[""]
var res1: String = b[""]

// Everything works fine now.

2 - Subclass it from NSObject
class A: NSObject  { 
…
}
- Now it shows an error
“Subscript getter with Objective-C selector 'objectForKeyedSubscript:' conflicts with previous declaration with the same Objective-C selector”

Expected Results:
It should be possible to have multiple subscripts

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!