ios - Reading values .plist swift -
i have .plist in swift. set follows

i have trouble finding information on how read information .plist. want able randomly select 1 of 845 items in emojilist. once have item, want have access item's emoji string value , description string value.
programatically how go accessing random item inside item list? , having access specific item's properties?
first load plist in array of dictionaries. each dictionary represents 1 emoji. generate random index of array, , pull out dictionary @ index. use dictionary access properties of emoji.
var emojiarray: nsarray? if let path = nsbundle.mainbundle().pathforresource("name-of-file", oftype: "plist"){ emojiarray = nsarray(contentsoffile: path) } if let array = emojiarray { let randomindex = arc4random_uniform(array.count) // random number 0 array.count - 1 let emojidictionary = array[randomindex] println("emoji value: \(emojidictionary["emoji"]), emoji description: \(emojidictionary["description"])" }
Comments
Post a Comment