mercredi 20 juillet 2016

Synchronizing JSON file with Random generator in Swift

I have made a JSON file with all of the information which should be populated in the random generator in my swift project. Any ideas how can I synchronise that data with my swift project?

Example of my JSON file:

“People”: {
    “Person1”: {
        “Label1.text”: “Безплатна Бира”,
        “ImeNaObekt.text”: “Царево”,
        “Shirina.text”: “44.0757”,
        “Duljina.text”: "25.6172"
    },

    “Person2”: {
        “Label1.text”: “Безплатно Кафе”,
        “ImeNaObekt.text”: “Царево”,
        “Shirina.text”:”43.1757”,
        “Duljina.text”: "24.5172"
}

}

example of my random generator:

func parseJSON()
        {
            let path: String = NSBundle.mainBundle().pathForResource("jsonFile", ofType: "json") as String!
            let jsonData = NSData(contentsOfFile: path) as NSData!
            let ReadableJSON = JSON ( data:jsonData, options: NSJSONReadingOptions.MutableContainers, error: nil )

        let RandomWordGen = arc4random_uniform(5)

        switch (RandomWordGen) {

        case 0:
            Label1.text = "Безплатна Бира"
            ImeNaObekt.text = "Златни пясъци"
            Imageview.image = UIImage (named: "bira.jpg")
            Shirina.text = "44.0757"
            Duljina.text = "25.6172"
            Navime.hidden = false
            Navime.enabled = true
            break
        case 1:
            Label1.text = "Безплатно Кафе"
            ImeNaObekt.text = "Златни пясъци"
            Imageview.image = UIImage (named: "kafe.jpg")
            Shirina.text = "43.1757"
            Duljina.text = "24.5172"
            Navime.hidden = false
            Navime.enabled = true
            break




Aucun commentaire:

Enregistrer un commentaire