Save class doesn't work with swift and xcode

Hey! I’ve been sitting with this problem for hours. Really hope you can help me!
Everything in my app works with user registration etc. But when it comes to store something in the database I really can’t get it to work.
I get this error:
"warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
(lldb) "
My code (directly from the documentation docs):
class Contact : NSObject {

var objectId : String?
var name : String?
var age: Int?
var phone : String?
var title : String?
}
func saveNewContact() {

let contact = Contact()
contact.name = “Jack Daniels”
contact.age = 47
contact.phone = “777-777-777”
contact.title = “Favorites”

let backendless = Backendless.sharedInstance()
let dataStore = backendless.data.of(Contact.ofClass())

// save object synchronously
var error: Fault?
let result = dataStore.save(contact, fault: &error) as? Contact
if error == nil {
print(“Contact has been saved: (result!.objectId)”)
}
else {
print(“Server reported an error: (error)”)
}

}
I then call saveNewContact() from a button.
Note: I’m a newbie so hope you can bare with me :slight_smile:

hi rasmus,

Please, change the Contact class:

class Contact : NSObject {

var objectId : String?

var name : String?

var age: Int = 0

var phone : String?

var title : String?

}

The numeric and boolean property must be initialized, it cannot be optional.
The documentation will be fixed.

Regards,
Slava

Hey Slava, thanks for your reply.

I tried to change it and I still get the same error. Have I done anything wrong? Here’s my full code:

import UIKit

class SkrivPost: UIViewController {

    @IBOutlet weak var DitNavn: UITextField!
    @IBOutlet weak var Indhold: UITextView!
    @IBOutlet weak var SkrivFelt: UITextField!
    
    class Contact : NSObject {
        
        var objectId : String?
        var name : String?
        var age: Int = 0
        var phone : String?
        var title : String?
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

       
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
 
    
    func saveNewContact() {
        
        let contact = Contact()
        contact.name = "Jack Daniels"
        contact.age = 47
        contact.phone = "777-777-777"
        contact.title = "Favorites"
        
        let backendless = Backendless.sharedInstance()
        let dataStore = backendless.data.of(Contact.ofClass())
        
        // save object synchronously
        var error: Fault?
        let result = dataStore.save(contact, fault: &error) as? Contact
        if error == nil {
            print("Contact has been saved: \(result!.objectId)")
        }
        else {
            print("Server reported an error: \(error)")
        }
        

    }
    
    // Write message button
    @IBAction func PostDet(sender: AnyObject) {
        
        saveNewContact()
        
    }

}

I can also confirm that initialising the numeric/boolean fields first doesn’t prevent the exception being thrown.

This is the same issue as my ticket raised here: http://support.backendless.com/t/exception-thrown-every-time-when-saving-data-object-swift-ios-9-2-sdk-3-0-8

Hi Rasmus,

You should implement the data classes OUTSIDE of ViewController class, maybe you could implement them in a separate file(s).

So, move Contact class outside the SkrivPost class - and all will be OK.

Regards,
Slava

Thanks for the help! Vyacheslav Vdovichenko.
It works now.