print("\n============ Fetching first page using the ASYNC API ============")
let startTime = NSDate()
let query = BackendlessDataQuery()
backendless.persistenceService.of(Restaurant.ofClass()).find(
query,
response: { ( restaurants : BackendlessCollection!) -> () in
let currentPage = restaurants.getCurrentPage()
print(“Loaded (currentPage.count) restaurant objects”)
print(“Total restaurants in the Backendless starage - (restaurants.totalObjects)”)
for restaurant in currentPage as! [Restaurant] {
print(“Restaurant name = (restaurant.status)”)
}
print(“Total time (ms) - (1000*NSDate().timeIntervalSinceDate(startTime))”)
},
error: { ( fault : Fault!) -> () in
print(“Server reported an error: (fault)”)
}
)
}
I am very confused right now , i have created a new project and tested this and it works but in my current app i test it and it gaves me this error ============ Fetching first page using the ASYNC API ============
Loaded 4 restaurant objects
Total restaurants in the Backendless starage - 4
fatal error: NSArray element failed to match the Swift Array Element type
(lldb)
class Location : NSObject {
var objectId : String?
var created : NSDate?
var updated : NSDate?
var ownerId : String?
var phoneNumber : String?
var streetAdress : String?
var city : String?
}
class Restaurant : NSObject {
var objectId : String?
var created : NSDate?
var updated : NSDate?
var ownerId : String?
var name : String?
var cuisine : String?
var locations : [Location]?
var owner : BackendlessUser?
}
class ViewController: UIViewController {
let APP_ID = "CF47722D-EB7B-A0D0-FFE3-1FADE3346100"
let SECRET_KEY = "43B43EF7-247A-ED56-FF2F-ECD43C6E9000"
let VERSION_NUM = "v1"
var backendless = Backendless.sharedInstance()
override func viewDidLoad() {
super.viewDidLoad()
backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)
fetchingFirstPageAsync()
}
func fetchingFirstPageAsync() {
print("\n============ Fetching first page using the ASYNC API ============")
let startTime = NSDate()
let query = BackendlessDataQuery()
backendless.persistenceService.of(Restaurant.ofClass()).find(
query,
response: { ( restaurants : BackendlessCollection!) -> () in
let currentPage = restaurants.getCurrentPage()
print("Loaded \(currentPage.count) restaurant objects")
print("Total restaurants in the Backendless starage - \(restaurants.totalObjects)")
for restaurant in currentPage as! [Restaurant] {
print("Restaurant name = \(restaurant.name)")
}
print("Total time (ms) - \(1000*NSDate().timeIntervalSinceDate(startTime))")
},
error: { ( fault : Fault!) -> () in
print("Server reported an error: \(fault)")
}
)
}
}
It is damn weird on xcode i move everything from my current app to a new project it works but on my current project it damn error . I hope anyone can explain why but it seems like it compiler bug or something . I have solve it by moving all my file to a new project dk why is this happening