The problem is changing the signature of the method, as Kashif suggested. Swift does not seem to be able to switch to the Objective-C method because the signature no longer matches the names of the subscripts.
Workaround 1
You can get around this without changing the structure by calling the substring method directly, instead of using the [] operator:
Instead of using the instructions below to get the value of a specific key:
let str = user["key-name"] as? Bool
Please use the following instructions:
let str = user.objectForKey("key-name") as? Bool
and
Instead of using the instructions below to set the value of a specific key:
user["key-name"] = "Bla bla"
Please use the following instructions:
user.setObject("Bla bla", forKey: "key-name")
Workaround 2
Another solution is to add an extension to PFObject that implements the subscript element and calls setValue:forKey: ::
extension PFObject { subscript(index: String) -> AnyObject? { get { return self.valueForKey(index) } set(newValue) { if let newValue: AnyObject = newValue { self.setValue(newValue, forKey: index) } } } }
Note that this second workaround is not entirely safe, since I'm not sure how Parse implements substring methods (maybe they do more than just call setValue:forKey ), it worked in my simple test cases, so it seems like A valid workaround until it is committed to Parse / Swift.
Ben-g
source share