Hello:
I have the file below that I am trying to get Swift to parse and do a readout of the file in the debug area but it is not parsing the file.
Here is the .json file that I converted to a .plist file with terminal plutil converter:
(I can't copy the plist file. Is there a way to copy it?)
[
{
"questionId":"359",
"difficulty_level":"80",
"subject":"MATH",
"question":"There are 5 children in the first row and 6 in the second row. All in the first row have pencils, and 2 in the second row have them. How many more pencils are needed?",
"distractor_1":"6",
"distractor_2":"3",
"distractor_3":"4",
"distractor_4":"11",
"distractor_5":"NH",
"answer":"3",
"id":"357",
"q_value":"1530",
"grade":"2",
"topic":"WORD PROBLEMS",
"qid":"1"
}
]
Here is the Swift Code:
mport Cocoa
import CoreData
import Foundation
class ViewController: NSViewController, NSApplicationDelegate {
var username: String = "Anonymous"
override func viewDidLoad() {
super.viewDidLoad()
preloadData()
// Do any additional setup after loading the view.
}
func preloadData() {
let preloadedDataKey = "didPreloadTest"
let userDefaults = UserDefaults.standard
if userDefaults.bool(forKey: preloadedDataKey) == false {
guard let urlPath = Bundle.main.url(forResource: "test1", withExtension: "plist") else{
return
}
if let arrayContents = NSArray(contentsOf: urlPath) as? [String] {
for scqName in arrayContents {
print (scqName)
}
}
}
}
}