我正在尝试保存创建的事件的对象ID。我已经尝试了异步和同步保存并将对象ID保存在变量中。但我无法从其他类访问对象id的值,但我能够从事件类中访问其他变量
class Event: NSObject, MKAnnotation {
var userImage:UIImage!
var userName:String!
var creatoruserName:String!
var segueIdenifier:String!
var eventId:String!
....
func addToDB() {
let event = PFObject(className:"Event")
let currentUser = PFUser.currentUser()
event["createdBy"] = currentUser
event["eventType"] = self.eventType
event["eventAttributes"] = attributes
event["eventDate"] = time
event["locationDescription"] = locationAsString
if (locationAsPoint != nil){
event["Location"] = locationAsPoint
try! event.save()
self.eventId = event.objectId!
print("objectId1 \(eventId!)")
print("objectId2 \(self.eventId!)")
try! event.save()
// event.saveInBackgroundWithBlock {
// (success: Bool, error: NSError?) -> Void in
// if (success) {
// print("event created")
// // The object has been saved.
// print("event.objectId! \(event.objectId!)")
// self.eventId = event.objectId!
// temp_objectId = event.objectId!
// print("self.objectId! \(self.eventId!)")
//// event.seteventID((event.objectId)!)
//
// } else {
// // There was a problem, check error.description
// }
// }
}
// print("objectId1 \(self.objectId!)")
}
调用此函数时,将打印objectId1的值。 当我从segue传递这个时,它不会打印objectid的值。 我错过了什么?
if (segue.identifier == "findOutMore") {
let svc = segue.destinationViewController as! CustomProfileViewController;
svc.event = self.eventSelected
print ("event id1 is \(eventSelected.geteventID())")
它打印nil coz我已经创建了geteventID,如果值为nil,则将其放入其中。