0
votes

I am currently trying to add the current user to a list of arrays in my Parse.com database. The database has a column of type array with the name "Likers". I am getting the following error when trying to append the username to the array when they press a button.

Cannot invoke 'append' with an argument list of type '(String?)'

My code is posted below. If somebody could give me some insight as to how I can solve this issue that would be great. I am currently running xCode 6.3 with Swift 1.2.

@IBAction func likedTapped(sender: AnyObject) {

    var user = PFUser.currentUser()?.username

    var likers = ["Likers"]

    ["Likers"].append(user) // <-- This is where I get the error above

}
1

1 Answers

0
votes

In this line:

var likers = ["Likers"]

You are declaring an array of String's called likers with the value of a string "Likers".

Then in this line:

["Likers"].append(user)

You should be using the declared likers variable like this.

likers.append(user)

Hopefully this explains how you are utilising your array declaration wrong. However, you are also approaching Parse data storage incorrectly as they need to be stored to parse using Parse objects.

Some information on parse object creation can be found here.

This is definitely worth reading to help understand using Parse.