Thread 1: EXC_BAD_ACCESS - iOS - Swift

Hi,

I am having a difficult time figuring out why I am getting Thread 1: EXC_BAD_ACCESS error when I run my app. When I comment out the fetchingFirstPageAsync() call viewDidLoad(), the error is not thrown.

here is my viewDidLoad()









    override func viewDidLoad() {

        super.viewDidLoad()

        backendless.initApp(APP_ID, secret:SECRET_KEY, version:VERSION_NUM)




        fetchingFirstPageAsync()

        

        

        tableView.reloadData()

        

    }

and here is my Backendless function:









    func fetchingFirstPageAsync() {

        

        print("\n============ Fetching first page using the ASYNC API ============")

        

        let startTime = NSDate()

        

        let query = BackendlessDataQuery()

        backendless.persistenceService.of(coffee_details.ofClass()).find(

            query,

            response: { (results : BackendlessCollection!) -> () in

                let currentPage = results.getCurrentPage()

                




                print("Loaded \(currentPage.count) restaurant objects")

                

                

                for result in currentPage as! [coffee_details] {

                    

                    print("Restaurant name = \(result.name)")

                    

                }

                

                print("Total time (ms) - \(1000*NSDate().timeIntervalSinceDate(startTime))")

            },

            error: { ( fault : Fault!) -> () in

                print("Server reported an error: \(fault)")

            }

        )

    }

    

}

and here is my object:









import Foundation




class coffee_details: NSObject {

    var name : String?

    var objectId : String?

    //var telephone : String?

    var address : String?

    var hours : String?

}

Any insight would be appreciated.

Thank you,
-Corbin

Hi Corbin,

Have you tried debugging the app (going line by line with the debugger) to see where the failure occurs?

Regards,
Mark

Hi Mark,

Yeah, I believe it’s happening after the response is requested. Instead of returning the data.

It happens on this line:
response: { (results : BackendlessCollection!) -> () in
and falls into this error:
error: { ( fault : Fault!) -> () in

Hi Corbin,

Maybe you need to remove the line:
tableView.reloadData()

I checked your sample, it works fine for me:

  • data model class:
class coffee_details: NSObject {
    var name : String?
    var objectId : String?
    var address : String?
    var hours : String?
}
  • creating method:
    func saveNewCoffeeDetails() {
        
        for i in 0 ..< 10 {
            
            let num = coffee_details()
            num.name = backendless.randomString(10)
            let dataStore = backendless.data.of(coffee_details.ofClass())
            // save object synchronously
            var error: Fault?
            let result = dataStore.save(num, fault: &error) as? coffee_details
            if error == nil {
                print("Data has been saved: \(i)->\(result!.objectId)")
            }
            else {
                print("Server reported an error: \(error)")
            }
        }
    }
  • fetching method:
    func fetchingCoffeeDetailsAsync() {
        
        print("\n============ Fetching first page using the ASYNC API ============")
        
        let startTime = NSDate()
        let query = BackendlessDataQuery()
        
        backendless.persistenceService.of(coffee_details.ofClass()).find(
            query,
            response: { (results : BackendlessCollection!) -> () in
                
                let currentPage = results.getCurrentPage()
                print("Loaded \(currentPage.count) coffee_details objects")
                for result in currentPage as! [coffee_details] {
                    print("coffee_details name = \(result.name)")
                }
                
                print("Total time (ms) - \(1000*NSDate().timeIntervalSinceDate(startTime))")
                
            },
            
            error: { ( fault : Fault!) -> () in
                print("Server reported an error: \(fault)")
            }
        )
    }

Here is a log:
http://support.backendless.com/public/attachments/f837cb66d2af9369ea881367d335dbc9.png&lt;/img&gt;
Regards,
Slava

Hi Slava,

I don’t have a creating method, I just want to print to the console for now. Is it critical for saveNewCoffeeDetails() to be called? if so, where is it called? in viewDidLoad? I removed the tableView.reloadData() and I still get the memory error stepping into this call: fetchingCoffeeDetailsAsync()

Thanks,

I simply made saveNewCoffeeDetails() to be able to check fetchingCoffeeDetailsAsync() in my Backendless app.

I created a sample project with your class (see in attachment), you can try it with my Backendless app, then set appId & secretKey of your Backendless app, and compare the results. This allows you to check SDK ‘find’ call without any additional elements. If you will be able to get your coffee_details objects with this sample app, then SDK works right and the issue is in your app code. Let me know how it goes here.

Regards,
Slava

TestFeaturingData.zip (19.26MB)