我试图将我的xcode项目运行到我的iPhone上,但每当我尝试运行它时,我都会
使用'下标'
但是,如果我在xcode模拟器上运行该项目,它工作正常吗?有任何想法吗? 继承人的代码
for ev in jsonObject! {
let catName = ev["CATEGORY_NAME"]
let venName = ev["EVENT_VENUES"]
let shortName = ev["SHORT_NAME"]
let eventName = ev["EVENT_NAME"]
let dsc = ev["EVENT_DESCRIPTION"]
let img = ev["EVENT_IMAGE"]
if let category = catName, theShortName = shortName, theEventName = eventName, theDesc = dsc, theImg = img, theVenues = venName{
if theVenues.count < 1 {
continue
}
if let fv = theVenues[0]{
if let vn = fv["VENUE_NAME"] as? String {
let event = Event(data: ["CATEGORY_NAME" : category, "SHORT_NAME" : theShortName,"EVENT_NAME" : theEventName,"EVENT_DESCRIPTION" : theDesc,"EVENT_IMAGE" : theImg,"VENUE_NAME" : vn])
self.events.append(event!)
}
}
}
}
我在这一行收到错误
if let fv = theVenues[0]{
这是数据初始化的地方
class Event {
var shortName : String?
var name : String?
var desc : String?
var category : String?
var location : String?
var image : String?
// pass data object directly into initializer.
init?(data: [String:AnyObject]) {
guard let eventShortName = data["SHORT_NAME"] as? String else { return }
guard let eventName = data["EVENT_NAME"] as? String else { return }
guard let eventDesc = data["EVENT_DESCRIPTION"] as? String else { return }
guard let categoryName = data["CATEGORY_NAME"] as? String else { return }
guard let eventLocation = data["VENUE_NAME"] as? String else { return }
guard let eventImage = data["EVENT_IMAGE"] as? String else { return }
shortName = eventShortName
name = eventName
desc = eventDesc
category = categoryName
location = eventLocation
image = eventImage
}
}