Hello:
I am getting the error Value of Type Bool has no subscripts in bellow code but can't figure out how to resolve it. Any help will be appreciated.
The error is on line # 19. That line is supposed to call first record and continue with subsequest records in the plist.
func preloadData() {
print ("Call to preload Data Starts Now")
let preloadedDataKey = "didPreloadData"
UserDefaults.standard.removeObject(forKey: preloadedDataKey)
let userDefaults = UserDefaults.standard
if userDefaults.bool(forKey: preloadedDataKey) == false {
guard Bundle.main.url(forResource: "SCQ", withExtension:"plist") != nil else {
return
}
var propertyListFormat = PropertyListSerialization.PropertyListFormat.xml //format the property list
var plistData: [String: AnyObject] = [:] // the data
print(plistData)
let plistUrl = Bundle.main.url (forResource: "SCQ", withExtension: "plist") // path of the data
let fileManager = FileManager.default
if let plistData = NSData(contentsOf: plistUrl!) {
var format = PropertyListSerialization.PropertyListFormat.xml
do {
let items = PropertyListSerialization.propertyList(plistData, isValidFor: format)
let item = items[0]// error here
if let attribute = item ["answer"] {
print (item)
}
if let attribute = item ["distractor1"] {
print (item)
}
if let attribute = item ["distractor2"] {
print (item)
}
if let attribute = item ["distractor3"] {
print (item)
}
if let attribute = item ["distractor4"] {
print (item)
}
if let attribute = item ["distractor5"] {
print (item)
}
if let attribute = item ["grade"] {
print (item)
}
if let attribute = item ["id"] {
print (item)
}
if let attribute = item ["answer"] {
print (item)
}
if let attribute = item ["qid"] {
print (item)
}
if let attribute = item ["question"] {
print (item)
}
if let attribute = item ["qValue"] {
print (item)
}
if let attribute = item ["skill"] {
print (item)
}
if let attribute = item ["subject"] {
print (item)
}
if let attribute = item ["topic"] {
print (item)
}
} catch {
print(error)
}
}