phil phil - 4 months ago 64
Swift Question

Binary operator '==' cannot be applied to operands of type '(UIViewController, sender: AnyObject?) -> Void' and 'String'

Hi Im having an issue with swift 3. there is this bit of code thats giving me an error. I converted it from swift 2.2 to swift 3 and this was the outcome

the few lines of code was swift 2 code and it work fine

the second bit of code is the converted one and its giving me an error

and if I use "=" instead of "==" it gives me this error

if show = "followers" {
loadFollowers()
}


if show = "followings" {
loadFollowings()
}


}


Cannot assign to property: self is immutable


its the if statement that is causing the error

var user = String()
var show = String()

class followersViewController: UITableViewController {


var usernameArray = [String]()
var picArray = [PFFile]()


var followArray = [String]()



override func viewDidLoad() {
super.viewDidLoad()






self.navigationItem.hidesBackButton = true
let backBtn = UIBarButtonItem(image: UIImage(named: "back.png"), style: .plain, target: self, action: #selector(followersVC.back(_:)))
self.navigationItem.leftBarButtonItem = backBtn


let backSwipe = UISwipeGestureRecognizer(target: self, action: #selector(followersVC.back(_:)))
backSwipe.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(backSwipe)



if show == "followers" {
loadFollowers()
}


if show == "followings" {
loadFollowings()
}

}



Binary operator '==' cannot be applied to operands of type '(UIViewController, sender: AnyObject?) -> Void' and 'String'

dan dan
Answer

In Swift 3, UIViewController has a method named show which is shadowing your show variable and preventing your view controller from using it.

You can fix the issue by changing the name of your show variable to something else and using the == comparison.

Comments