0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ObjC to Swift : NSDictionary to Swift Dictionary

Last updated at Posted at 2015-05-03

Objective-C

NSString * objCString = @"String";
BOOL objCBool = YES;

NSDictionary * dictionary = @{ @"stringKey" : objCString,
                               @"boolKey"   : [NSNumber numberWithBool: objCBool] };

NSString * stringInDictionary = dictionary[@"stringKey"];
BOOL boolInDictionary = [[NSNumber numberWithBool: dictionary[@"boolKey"]] boolValue];

Swift

let swiftString = "String"
let swiftBool = true

dictionary: Dictionary = [ "stringKey" : swiftString,
                           "boolKey"   : swiftBool ]

let stringInDictionary = dictionary["stringKey"] as! String
let boolInDictionary = dictionary["boolKey"] as! Bool
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?