ios - Reading values .plist swift -


i have .plist in swift. set follows

enter image description here

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

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -