Assumptions/What you want to realize
I'm making a diary app with Swift.
The xcode version is 7.3.1, and the swift version is 2.2.
Problem/error message you are experiencing
When you start writing code in xcode, the SourceKitService crashes more often than you can.
mBaaS Nifty Cloud Mobile Backend Data Retrieval Method
query.findObjectsInBackgroundWithBlock({(objects, errors)in
We found that commenting out prevents crashes.
I understand the problem, but I don't know how to fix it.Please let me know if you know anything.Thank you.
The total code that appears to be a problem is as follows:
let query=NCMBQuery(className: "user")
query.whereKey("userName", equalTo:user[0].uuid)
// Here's the cause of the sourcekit crash!!I'm sure this is the cause, so I'll check it out in more detail!!
query.findObjectsInBackgroundWithBlock({(objects, errors)in
if error == nil {
objects[0].setObject(self.userNameTextField.text, forKey: "ownerName")
objects[0].setObject(self.userSelectWork, forKey: "works")
objects[0].setObject(self.userSelectWorksYear, forKey: "worksYear")
objects[0].setObject(self.myGoalTextView.text, forKey: "myGoal")
if self.pickedPhoto!=nil{
objects[0].setObject(self.targetFile?.name, forKey: "userPhotoName")
}
objects[0].save(&saveError)
let realm=try!Realm()
let user=User()
user.id = 1
user.userName=self.userNameTextField.text
user.works=self.userSelectWork
user.worksYear=self.userSelectWorksYear!
user.myGoal=self.myGoalTextView.text
try!realm.write({
})
print("hi")
letfileName=NSUUID().UUIDString+".jpg"
let filePath=(self.path!as NSSstring).stringByAppendingPathComponent(fileName)
if self.photo?.writeToFile(filePath, atomically:true) == false{
self.errorMessage()
} else {
print("Photos saved to file")
}
// If you have a photo
if self.targetFile!=nil{
// If it is not the same as the photo of the data to be updated
if self.targetFile?.name!=objects[0]["userPhotoName"] as!String{
self.targetFile?.saveInBackgroundWithBlock({(error:NSError!)in
if error == nil {
self.navigationController?popToRootViewControllerAnimated(true)
} else {
self.errorMessage()
}
}, progressBlock: {(percentDone)in
})
}
} else {
// If you don't have a picture
self.navigationController?popToRootViewControllerAnimated(true)
}
} else {
// Error handling
self.errorMessage()
}
})
}
Supplemental
The other day, I asked a question about the same problem and it has not been solved yet, but as I looked into it, I found something I would like to ask more questions, so I posted a new one.
SourceKitService terminated for an unexpected reason.What to do with the error
Also, I have been asking questions on other sites, but it has not been resolved yet, so I asked you a question.
https://teratail.com/questions/34217?complete=
The contents of the objects retrieved by findObjectsInBackgroundWithBlock were incorrectly retrieved with objects[0].userName, and the correct values were objects[0].objectsForKey().This incorrect code caused frequent sourceKit crashes.
© 2024 OneMinuteCode. All rights reserved.