1

I am trying to create a game integrated to game center at the same time stores data to sqlite. I am using sqlite.swift for my sqlite functionalities. I need to submit a score to game center (scoring type-Integer) and that score is stored in my db with type Expression. Is there a way to typecast Expression to Int64 only? I tried doing this... gkScore.value = Int64(userQuery[overAllScore]) and this gkScore.value = (userQuery[overAllScore]) as Int64 but did not succeed.. :( Help please. Thanks

  • 1
    what is the error / why didn't it work – Daij-Djan Jul 10 '15 at 14:30
  • Quick test: if you do `let test = userQuery[overAllScore]` and then do ALT+CLICK on `test`, what does the popup say, what type is the value? – Eric Aya Jul 10 '15 at 14:36
  • Cannot assign a value of type '(Expression)' to a value of type 'Int64' – tryinghardladyprogrammer Jul 10 '15 at 14:39
  • if i simply put gkScore.value = userQuery[overAllScore] the error is 'Expression' is not convertible to 'Int64' that's why I tried typecasting it.. – tryinghardladyprogrammer Jul 10 '15 at 14:41
  • Thanks but that's not what I asked. :-) What does *the Xcode popup* say with the *exact line of code I wrote in my comment* when you do ALT+CLICK on this new `test` variable? The idea is to make a test separated from your existing variables. – Eric Aya Jul 10 '15 at 14:44
  • oh sorry I misunderstood your comment.. this is what xcode says: let test: Expression – tryinghardladyprogrammer Jul 10 '15 at 14:48
  • No worries. Ok, so now we know that the problem isn't with `gkScore.value`, that's what I wanted to be sure of. The thing is normally you should get an Int64 as the result, not an Expression: `userQuery` should be of type "subscript column ..." and `overAllScore` should be of type `Expression`, and it should give a result of what the expression returns from the column, not the expression itself. – Eric Aya Jul 10 '15 at 14:53
  • So I don't know where exactly is the error but it's not because of `gkScore.value = Int64(userQuery[overAllScore])` which should work if indeed the content of your column is an Int. My guess is you have a problem elsewhere with either `userQuery` or `overAllScore`. – Eric Aya Jul 10 '15 at 14:54
  • i declared overAllScore this way.. `let overAllScore = Expression("score")` and added it as a column with `defaultValue=0`.. and defined `let userQuery = game.filter(gameid == Expression(id))` am i missing something? – tryinghardladyprogrammer Jul 10 '15 at 15:02
  • Well I just deleted my previous comment because actually it doesn't look ok. Your `userQuery`, aptly named, is surely of type `Query` because you're using filter successfully, but the way you use it later to get values it should be a *row* (you should see "subscript column ..." when you ALT+CLICK on it). So yes, you must be missing a step somewhere. Unfortunately I can't help further without knowing your codebase and how you init the DB and the columns. – Eric Aya Jul 10 '15 at 15:11
  • oh, i already figured it out.. yeah.. there's something wrong with my userQuery.. I treated it as a row instead of a Query.. big thanks! :) – tryinghardladyprogrammer Jul 10 '15 at 15:18

0 Answers0