ParseSwift не сохраняет Int в столбец – undefinedIOS

Программируем под IOS
Ответить
Гость
 ParseSwift не сохраняет Int в столбец – undefined

Сообщение Гость »


У меня есть простой объект 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
}
}
Then I save a GameScore object to the server by calling this function:

Код: Выделить всё

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)")
}
}
}
Now, when I save this object to the Parse server it saves it but the property is always undefined. What am I doing wrong? I also tried incrementing the property and the increment() operation by 1 for example works as expected and the score becomes 1. But it never accepts the initial value I set the score to be.
This 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)
does have a score of 100 or something undefined. So maybe the issue is with my Parse server not showing this Int value properly in the dashboard? It's very strange. However, it does show the property correctly that also is on the GameScore object. Also, after fetching the GameScores from the server, the newest created GameScore looks like has an undefined score instead of what the response callback says. So the server is not saving the Int value for some reason.
Update 2
I created another column in Parse server and a corresponding property in my GameScore object called (just like example shows) just to test it out. With , it saves the initial value I give it correctly! I don't know what the issue is with but maybe it's a keyword or something that's not working.


Источник: https://stackoverflow.com/questions/767 ... -undefined
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»