-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONHelper.swift
More file actions
37 lines (30 loc) · 1.25 KB
/
JSONHelper.swift
File metadata and controls
37 lines (30 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// JSONHelper.swift
// Comics
//
// Created by Andrey Apet on 16.11.16.
// Copyright © 2016 Andrey Apet. All rights reserved.
//
import UIKit
import SwiftyJSON
import Foundation
class JSONHelper: NSObject {
func GetJsonFromFile(filename:String) ->JSON {
let file = Bundle.main.path(forResource: filename, ofType: "json")
let data = NSData(contentsOfFile: file!) as NSData!
let json = JSON(data: data! as Data, options: JSONSerialization.ReadingOptions.mutableContainers , error: nil)
return json
}
func getInfoOfTemplateFromJson(indexTemplate: Int) -> [Int:[String:Float]] {
let json = GetJsonFromFile(filename: "TopApps")
var param = [Int:[String:Float]]()
let numberOfElements = json["template\(indexTemplate)"].count
for i in 0..<numberOfElements {
param[i] = ["x":json["template\(indexTemplate)"]["\(i)"]["x"].floatValue]
param[i]!["y"] = json["template\(indexTemplate)"]["\(i)"]["y"].floatValue
param[i]!["width"] = json["template\(indexTemplate)"]["\(i)"]["width"].floatValue
param[i]!["height"] = json["template\(indexTemplate)"]["\(i)"]["height"].floatValue
}
return param
}
}