标签:
1 import UIKit 2 3 class MainTabBarViewController: UITabBarController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 //1.获取json文件的地址 8 guard let jsonPath = NSBundle.mainBundle().pathForResource("MainVCSettings.json", ofType: nil) else { 9 return 10 } 11 //2.获取json文件的数据 12 guard let jsonData = NSData(contentsOfFile: jsonPath) else { 13 return 14 } 15 //3.将json文件的数据转化为swift可读数据 16 guard let anyObject = try? NSJSONSerialization.JSONObjectWithData(jsonData, options: .MutableContainers) else { 17 return 18 } 19 20 guard let dicArray = anyObject as? [[String:AnyObject]] else { 21 return 22 } 23 //4.提取json文件数据 24 for dic in dicArray { 25 //4.1提取数据 26 guard let vcName = dic["vcName"] as? String else { 27 continue 28 } 29 guard let title = dic["title"] as? String else { 30 continue 31 } 32 guard let imageName = dic["imageName"] as? String else { 33 continue 34 } 35 //4.2添加控制器 36 addChildViewController(vcName, title: title, imageName: imageName) 37 } 38 }
标签:
原文地址:http://www.cnblogs.com/igeniuswwh/p/5947582.html