Swift 3.0.2 gives an ambitious error '' Type 'bool' broken '

I use this structure and using this

struct Ride {
  var isRideForNow: Bool!    
}
 var sheduleRide: Ride?
 sheduleRide = Ride()
 sheduleRide?.isRideForNow = false

When I use this, it works great

 if (sheduleRide?.isRideForNow)! {
   //some code
 }

But I don’t know why the code below gives the error "The type" bool "is broken", even in it there is no additional binding

 if (sheduleRide!.isRideForNow) {
   //some code
 }
+4
source share
1 answer

This is a useless error message that appears only in Swift version 3.0 to 3.0.2. The problem is that Swift does not mean deploying optional, as it thinks you are trying to perform additional validation.

So the solution, as @vacawama says , is to simply explicitly expand the optional parameter:

if sheduleRide!.isRideForNow! {
    // some code
}

(, , , sheduleRide, isRideForNow nil)

, Swift IUO , , IUO, SE- 0054 - , IUO , , .

, . , :

if sheduleRide!.isRideForNow {
    // some code
}

Swift 3.1.

, @vadian , , isRideForNow IUO. , ( lazy).

, :

struct Ride {
    var isRideForNow: Bool
}

var sheduleRide = Ride(isRideForNow: false)
+6

Source: https://habr.com/ru/post/1674873/


All Articles