抱歉标题模棱两可。为了让我保存一个特定的对象,我需要查询它,它返回一个集合。编辑后如何保存该集合?
任何帮助表示赞赏。
func joinGroup() {
var group = Groups()
backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
self.backendless.userService.getPersistentUser()
let user = self.backendless.userService.currentUser
let whereClause = "UsersInGroup.objectId = '\(user.objectId)'"
let dataQuery = BackendlessDataQuery()
dataQuery.whereClause = whereClause
var error: Fault?
var dataStore = self.backendless.persistenceService.find(Groups.ofClass(),
dataQuery:dataQuery) as BackendlessCollection
for joiningroup in dataStore.data as! [Groups] {
joiningroup.UsersInGroup.append(user)
}
以下是对象的保存方式
func createGroup() {
let groups = self.backendless.persistenceService.of(Groups().ofClass())
backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
self.backendless.userService.getPersistentUser()
let user = self.backendless.userService.currentUser
var newGroup = Groups()
newGroup.groupName = "FromClient"
newGroup.ownerId = user.objectId
newGroup.UsersInGroup.append(user)
var error: Fault?
newGroup = groups.save(newGroup) as! Groups
if error == nil {
print("Created group: \(newGroup.groupName)")
}
else {
print("Server reported an error: \(error)")
}
}