Skip to content

Instantly share code, notes, and snippets.

@odrobnik
Created April 23, 2015 08:05
Show Gist options
  • Save odrobnik/a95d1542438abd1f914a to your computer and use it in GitHub Desktop.
Save odrobnik/a95d1542438abd1f914a to your computer and use it in GitHub Desktop.
AddressBook Dictionary
var dict = [
kABPersonAddressCityKey: "Vienna",
kABPersonAddressZIPKey: "1110",
kABPersonAddressStreetKey: "Rinnböckstrasse 48/17",
kABPersonAddressCountryKey: "Austria"
]
Error on line 1: "Type of expression is ambiguous without more context"
Error on line 2: "'_' is not convertible to 'StringLiteralConvertible'
@odrobnik
Copy link
Author

Why the "as!" ?

@kirsteins
Copy link

It seems CFString is not Hashable and cannot be a key. I guess inferring ambiguity is there, because it does bridge to String.

var dict: [String:String] = [
    kABPersonAddressCityKey: "Vienna",
    kABPersonAddressZIPKey: "1110",
    kABPersonAddressStreetKey: "Rinnböckstrasse 48/17",
    kABPersonAddressCountryKey: "Austria"
]

@AndrewHoos
Copy link

Could you just implement the Hashable Protocol for CFString? Something simple that does the cast and returns the NSString Hash.

@helje5
Copy link

helje5 commented Apr 24, 2015

Didn't try, but something like:

extension CFString : Equatable, Hashable {
  public var hashValue: Int {
    return (self as! String).hashValue
  }
}
public func ==(lhs: CFString, rhs: CFString) -> Bool {
  return (lhs as! String) ==  (rhs as! String)
}

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment