Last active
June 7, 2016 13:25
-
-
Save MariuszWisniewski/5b60b404b647384db3d4bfe11020cd9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import syncano_ios | |
class Game : SCDataObject { | |
var name : String = "" | |
} | |
class Score : SCDataObject { | |
var name : String = "" | |
var game : Game? = nil | |
} | |
class Test_Filtering: NSObject { | |
let syncanoWithIgnoringACL = Syncano.init(apiKey: "API KEY WITH IGNORE-ACL", instanceName: "INSTANCE NAME") | |
let syncanoForUsers = Syncano.init(apiKey: "API KEY WITHOUT IGNORE ACL", instanceName: "INSTANCE NAME") | |
func runTests() { | |
Game.registerClass() | |
Score.registerClass() | |
self.testFiltering() | |
self.testUserLogin() | |
} | |
func printScore(score: Score) { | |
print("Name: \(score.name)") | |
print("ID: \(score.objectId)") | |
print("Game ID: \(score.game?.objectId)") | |
print("Owner/User ID: \(score.owner)") | |
print("") | |
} | |
func testFiltering() { | |
//faking having the object from Syncano | |
let game = Game() | |
game.objectId = 156 | |
let predicate = SCPredicate.whereKey("game", isEqualToNumber: game.objectId) | |
Score.pleaseFromSyncano(syncanoWithIgnoringACL).giveMeDataObjectsWithPredicate(predicate, parameters: [:]) { scores, error in | |
guard error == nil, let scores = scores as? [Score] else { | |
print(error) | |
return | |
} | |
for score in scores { | |
print("Ignore ACL print") | |
self.printScore(score) | |
} | |
} | |
} | |
func testUserLogin() { | |
SCUser.loginWithUsername("username", password: "password", toSyncano:self.syncanoForUsers) { error in | |
guard error == nil else { | |
print("Error during login: \(error)") | |
return | |
} | |
print("Login success!") | |
//faking having the object from Syncano | |
let game = Game() | |
game.objectId = 156 | |
let predicate = SCPredicate.whereKey("game", isEqualToNumber: game.objectId) | |
Score.pleaseFromSyncano(self.syncanoForUsers).giveMeDataObjectsWithPredicate(predicate, parameters: [:]) | |
{ scores, error in | |
guard error == nil, let scores = scores as? [Score] else { | |
print(error) | |
return | |
} | |
for score in scores { | |
print("User Login print") | |
self.printScore(score) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment