Skip to content

Instantly share code, notes, and snippets.

@davidortinau
Created December 16, 2014 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidortinau/de6c2eab6929fc9b3745 to your computer and use it in GitHub Desktop.
Save davidortinau/de6c2eab6929fc9b3745 to your computer and use it in GitHub Desktop.
NSDictionary Obj-C to Swift
// attempt to recreate the dictionary in Swift
var style:[String:NSDictionary] = [
"$default" : [NSFontAttributeName : UIFont(name: "Raleway", size: 12)],
"strong" : [NSFontAttributeName : UIFont(name: "Raleway-Bold", size: 12)],
"h1" : [NSFontAttributeName : UIFont(name: "Raleway-Bold", size: 14)]
]
// use as an NSDictionary fails at runtime
style._bridgeToObjectiveC() as NSMutableDictionary
NSDictionary *style = @{
@"$default" : @{NSFontAttributeName : [UIFont fontWithName:@"Raleway" size:12]},
@"strong" : @{NSFontAttributeName : [UIFont fontWithName:@"Raleway-Bold" size:12]},
@"h1" : @{NSFontAttributeName : [UIFont fontWithName:@"Raleway-Bold" size:14]}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment