I am trying to simultaiously learn iOS, Swift 2, x-code, and how to use CloudKit (yeah, unlikely). This is frustrating due to lack of Swift 2.0 examples provided by Apple and the fact that there's a lot of out-of-date info on the web.
I have this code trying to get data out of the Cloud. Lines 40 & 41 throw "consecutive statements on a line must be separated by ';'" I don't understand the reason. I suspect I am conflating two different ways of using CloudKit in trying to hack something together from various examples.
I can get records out from iCloud, but I am struggling to understand how to get data out, that is, what's in values={ . . . }}> as shown in output at line 38.
If someone could point me in the direction of getting ICloudKit to work, I'd be greatful.
import Foundation
import CloudKit
protocol CloudKitDelegate {
func errorUpdating(error: NSError)
func modelUpdated()
}
class MovieDataBase {
var container : CKContainer
var publicDB : CKDatabase
let privateDB : CKDatabase
var delegate : CloudKitDelegate?
init() {
container = CKContainer.defaultContainer()
publicDB = container.publicCloudDatabase
privateDB = container.privateCloudDatabase
}
func getMovieData() {
let predicate = NSPredicate(value: true)
let sort = NSSortDescriptor(key: "creationDate", ascending: false)
let query = CKQuery(recordType: "Movies", predicate: predicate)
query.sortDescriptors = [sort]
publicDB.performQuery(query, inZoneWithID: nil) {
results, error in
if error != nil {
dispatch_async(dispatch_get_main_queue()) {
print("ERROR ", error!)
self.delegate?.errorUpdating(error!)
return
}
} else {
print(results)
let operation = CKQueryOperation(query: query)
operation.desiredKeys=["movieID","movieTitle"]
var movies = [MoviePromo]()
operation.recordFetchedBlock = { (results) in
let movies.movieID = results["movieID"] as! String
let movies.movieTitle = results["movieTitle"] as! String
}
}
}
}
}Movie Promo is defined as follows
import UIKit
class MoviePromo {
/
var movieID: String = ""
var movieTitle: String = ""
var moviePosterURL: String = ""
var movieLogLine: String = ""
var movieURL: String = ""
/
init?( movieID: String, movieTitle: String, moviePosterURL: String, movieLogLine: String, movieURL: String) {
self.movieID = movieID
self.movieTitle = movieTitle
self.moviePosterURL = moviePosterURL
self.movieLogLine = movieLogLine
self.movieURL = movieURL
}
/
func getMovieData() {
}
}