PickMe
PickMe

Reputation: 1

Swift - After updating to Parse SDK 1.7.4 - Error messages

i'm fairly new to Swift and Parse, however here's my problem: I downloaded a simple Swift/Parse app, adapted it and it worked fine until I decided to update the existing Parse SDK. I get errors over errors and I can't get it to work.

I'm not able to assign anything to currentuser anymore:

i.e.:

currentuser["location"] = PFGeoPoint(location: location)
currentuser["interestedCategory"] = self.pickerChoice
currentuser["locationLimit"] = Int(locationSlider.value)

I receive rolling error (also for Int, etc)

SettingViewController.swift:157:50: Cannot assign a value of type 'NSString!' to a value of type 'AnyObject?

'

or even

self.pickerChoiceRow = currentuser.objectForKey("interestedCategoryRow") as! Int

I get following error message:

SettingViewController.swift:82:36: Value of optional type 'PFUser?' not unwrapped; did you mean to use '!' or '?'?

Also this is not working anymore:

if currentuser["job1_objectId"] != nil {

......

} 

Because I receive the following error:

OverviewInsertViewController.swift:185:12: Binary operator '!=' cannot be applied to operands of type 'AnyObject?' and 'nil'

And this is also causing problems??!

var 1_objectId:NSString! = ""

self.1_objectId = currentuser["job1_objectId"] as! NSString
                    var query_jobs = PFQuery(className: "Jobs")
                    query_jobs.getObjectInBackgroundWithId(self.1_objectId as String) {
                        (object: PFObject!, error: NSError!) -> Void in
                        if (error == nil) {

For those lines I receive following errors:

OverviewInsertViewController.swift:144:77: Cannot assign a value of type 'NSString' to a value of type 'NSString!'

OverviewInsertViewController.swift:146:32: Cannot invoke 'getObjectInBackgroundWithId' with an argument list of type '(String, (PFObject!, NSError!) -> Void)'

Please help me, everything worked fine with the old Parse SDK?!

Upvotes: 0

Views: 254

Answers (1)

danielsalare
danielsalare

Reputation: 335

For the first point, when trying to update a value of an object, for example, the location, I used the following code:

    var query:PFQuery = PFQuery(className:"Location")
    query.whereKey("user", equalTo: PFUser.currentUser()!)
    //query Parse
    query.getFirstObjectInBackgroundWithBlock {
        (object: PFObject?, error: NSError?) -> Void in
        if error != nil || object == nil {
            println("The getFirstObject request failed.")
        } else if let object = object{
            // The find succeeded.
            println("Successfully retrieved the object.")

            object["location"] = point
            object.saveInBackground()
        }

    }

Please notice the "else if let object = object", adding that condition helped me with the first error you mentioned.

Hope it serves.

Upvotes: 0

Related Questions