Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Bound value in a conditional binding must be of Optional type

Tags:

ios

swift

if let ip = indexPath {
            var data: NSManagedObject = myList[ip.row] as NSManagedObject
            cell.textLabel?.text = data.valueForKeyPath("item") as String

         }

error : "Bound value in a conditional binding must be of Optional type"

I'm using xcode 6.1.1, help please.

I am following this tutorial, [http://www.youtube.com/watch?v=4ymz6i07DRM]

like image 212
suisied Avatar asked Dec 12 '22 01:12

suisied


1 Answers

You are saying:

if let ip = indexPath {

Swift is saying: "Just say let ip = indexPath, or simply use indexPath directly. There is no need for the if (or the curly braces); you don't need a condition here."

The reason is probably that at the time the tutorial you're using was designed, indexPath was an Optional and needed to be unwrapped. But now it is not an Optional. Apple changes the APIs from time to time.

like image 177
matt Avatar answered Jan 26 '23 01:01

matt