0
votes

Please someone help me. I have been stuck for over a week trying to fix these errors, searching all over but with no success.

I am sorry if this is an easy fix but I really have wasted so much time adding and changing stuff but to no avail. Any help will be extremely appreciated :)

//Update: Added complete code for Userviewcontroller, also thank you so much for replies I am so thankful :)

import UIKit
import Parse

class UserTableViewController: UITableViewController {

var users = [""]
var following = [Bool]()
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    println(PFUser.currentUser())

    var query = PFUser.query()

    query!.findObjectsInBackgroundWithBlock({ (objects: [AnyObject]!, error: NSError!) -> Void in

        self.users.removeAll(keepCapacity: true)

        for object in objects {

            var user:PFUser = object as! PFUser

            var isFollowing:Bool

            if user.username != PFUser.currentUser().username {

                self.users.append(user.username)

                isFollowing = false

                var query = PFQuery(className:"followers")
                query.whereKey("follower", equalTo:PFUser.currentUser().username)
                query.whereKey("following", equalTo:user.username)
                query.findObjectsInBackgroundWithBlock {
                    (objects: [AnyObject]!, error: NSError!) -> Void in
                    if error == nil {

                        for object in objects {

                            isFollowing = true

                        }

                        self.following.append(isFollowing)

                        self.tableView.reloadData()

                    } else {
                        // Log details of the failure
                        println(error)
                    }
                }

            }
        }
    })
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    println(following)
    return users.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell

    if following.count > indexPath.row {

        if following[indexPath.row] == true {

            cell.accessoryType = UITableViewCellAccessoryType.Checkmark
        }
    }
    cell.textLabel?.text = users[indexPath.row]

    return cell
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    var cell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!

    if cell.accessoryType == UITableViewCellAccessoryType.Checkmark {

        cell.accessoryType = UITableViewCellAccessoryType.None

        var query = PFQuery(className:"followers")
        query.whereKey("follower", equalTo:PFUser.currentUser()!.username!)
        query.whereKey("following", equalTo:cell.textLabel!.text!)
        query.findObjectsInBackgroundWithBlock {
            (objects: [AnyObject]!, error: NSError!) -> Void in
            if error == nil {

                for object in objects {
                    object.deleteInBackground()
                }
            } else {
                // Log details of the failure
                println(error)
            }
        }

    } else {

        cell.accessoryType = UITableViewCellAccessoryType.Checkmark

        var following = PFObject(className: "followers")
        following["following"] = cell.textLabel?.text
        following["follower"] = PFUser.currentUser()!.username

        following.saveInBackground()
    }
    }
}

//I am getting the ":

Cannot invoke 'findObjectsInBackgroundWithBlock' with an argument list of type '(([AnyObject]!, NSError!) -> Void)"

error I have tried every suggested solution and code change on stack overflow this is driving me crazy please help. Also I am getting this same thing on another line :(

I have attempted to switch the ! to ? pretty much everything you could think of. I am guessing it is an easy fix.

I will be extremely grateful for a fix

2
Not a Swift expert here, but is it possible the method doesn't like that "-> void" on the end? In the solution in the link below, it looks like that poster's invocation of "findObjectsInBackgroundWithBlock" has the same argument list, minus the "-> void" part. stackoverflow.com/questions/26512006/… - Jeff Mahoney
Can you properly paste the entire code? You're missing a lot of closing curly braces. Unless that is the problem. :| - MLQ
try with just query!.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in ... - BaSha
Show how you made them optional, they shouldn't be mandatory - Wain
Hi Guys, Thank you for quick replies. Sadly none of your suggestions fixed it :(. I have pasted my entire code, any help will be gladly appreciated :) - xedelta

2 Answers

0
votes

See this answer.

Why: Optionals changed in swift 1.2 (Xcode 6.3 update)

-1
votes

According to this question, the function that you should be calling is:

query!.findObjectsInBackgroundWithBlock({ (objects: [AnyObject]!, error: NSError!) in
    your code ...
})

So you have to remove -> Void from your function call.