Im trying to convert some Objective-C code to Swift but having trouble with it.
Heres the code:
@property (nonatomic, strong) NSMutableDictionary* loadedNativeAdViews;
@synthesize loadedNativeAdViews;
...
loadedNativeAdViews = [[NSMutableDictionary alloc] init];
...
nativeAdView = [loadedNativeAdViews objectForKey:@(indexPath.row)];
How would I write this in swift?
NSDictionaryis bridged to Swift native classDictionary, so you can use it wherever you usedNSDictionaryin Objective-C. For more information about this, take a look at Working with Cocoa Data Types apple docs.Swift is type safe, so you have to specify the kind of elements that you are using for the key and the value in the dictionary.
Assuming you are storing
UIViews on a Dictionary usingIntfor the key:Then access the elements stored in the dictionary: