Forgive the ignorance in advance; I am stumbling my way through Swift and JSON, and am diligently working to try to deconstruct tutorials and grasp a better understanding.
I have been using the SwiftyJSON example Xcode project (here). If I change the data of the SwiftyJSONTests.json file to include my own desired data, it properly renders when I run the project. My goal is to alter my AppDelegate.swift file to pull data from my live JSON page, rather than the example SwiftyJSONTests.json file.
My AppDelegate.swift file looks like so;
import UIKit
import SwiftyJSON
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let navigationController = self.window?.rootViewController as! UINavigationController
let viewController = navigationController.topViewController as! ViewController
if let file = NSBundle(forClass:AppDelegate.self).pathForResource("SwiftyJSONTests", ofType: "json") {
let data = NSData(contentsOfFile: file)!
let json = JSON(data:data)
viewController.json = json
} else {
viewController.json = JSON.nullJSON
}
return true
}
}
I've attempted altering my "let data = "... line to be a "let data = NSURL(contentsOfURL: url)!" and altering "SwiftyJSONTests" to my desired URL, but that's not even remotely close, it seems.
Is there any guidance one could provide to keep the structure of my Storyboard and AppDelegate intact, but have it point to a URL and not the file? I'm interested to learn and dissect.
Thanks so much!