Search code examples
iosswiftnsdictionaryrestkit

'[NSObject : AnyObject]' is not identical to 'NSDictionary', trouble with RKPathMatcher


I'm using RestKit, and calling "addFetchRequestBlock", in Swift.

Inside the block... umm, here's the code. easier to see it:

  RKObjectManager.sharedManager().addFetchRequestBlock { (url: NSURL!) -> NSFetchRequest! in
     let pathMatcher = RKPathMatcher(pattern: partialPath)

     var argsDict: [NSObject: AnyObject]
     let tokenize = false as Bool
     if (pathMatcher.matchesPath(url.relativePath, tokenizeQueryStrings: tokenize, parsedArguments: &argsDict)) {

......

It doesn't like "argsDict". (scroll code to right) The error reads

'[NSObject : AnyObject]' is not identical to 'NSDictionary'

Which is weird, b/c I thought it was. In any case, I can always switch the type to NSDictionary and save myself some trouble, but I'm wondering if I could do this with a "Dictionary" object, instead of an NSDictionary. For no other reason, than I'm trying to be more "swifty".


Solution

  • OK, found it under the "Autoreleasing Pointers" section in Apple Docs. Basically, types that are pointed to are not bridged.

    https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html

    Types that are pointed to are not bridged. For example, NSString ** comes over to Swift as AutoreleasingUnsafeMutablePointer<NSString?>, not AutoreleasingUnsafeMutablePointer<String?>.