У меня есть простой объект GameScore, определенный в документации (https://github.com/parse-community/Pars ... t%20Object .xcplaygroundpage/Contents.swift)
Код: Выделить всё
import Foundation
import ParseSwift
struct GameScore: ParseObject {
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
var originalData: Data?
// Your own properties
var score: Int?
var name: String?
func merge(with object: Self) throws -> Self {
var updated = try mergeParse(with: object)
if updated.shouldRestoreKey(\.score, original: object) {
updated.score = object.score
}
if updated.shouldRestoreKey(\.name, original: object) {
updated.name = object.name
}
return updated
}
}
extension GameScore {
init(score: Int) {
self.score = score
}
init(score: Int, name: String) {
self.score = score
self.name = name
}
init(objectId: String?) {
self.objectId = objectId
}
}
Код: Выделить всё
func createScore() {
var score = GameScore(score: Int(scoreScore), name: scoreName)
score.score = Int(scoreScore)
score.save { [weak self] result in
switch result {
case .success(let savedScore):
score = savedScore
self?.gameScore = savedScore
self?.fetchGameScores()
print("savedScore - score: \(score.score ?? 0), name: \(score.name ?? "")")
case .failure(let error):
print("save error: \(error.localizedDescription)")
}
}
}
Код: Выделить всё
scoreКод: Выделить всё
scoreThis should be very simple and easy to do yet it's not working and I don't understand why.
NOTE: I'm using the ParseSwift library and not the standard Parse iOS SDK that is in Obj-C.
Update
When I put a breakpoint in the save functions callback block, I do see that the savedScore in the:
Код: Выделить всё
case .success(let savedScore)Код: Выделить всё
nameUpdate 2
I created another column in Parse server and a corresponding property in my GameScore object called
Код: Выделить всё
pointКод: Выделить всё
pointКод: Выделить всё
scoreИсточник: https://stackoverflow.com/questions/767 ... -undefined
Мобильная версия