0

I've searched pretty thoroughly to no avail. I can't quite figure out why this statement isn't working. I'm trying to filter objects where the truckVIN contains the srchString.

Is this statement actually checking "Optional(..." instead of just "hl3"?

I appreciate the help!

let truckVIN = item.valueForKey(x.type.uppercaseString) as! String
let srchString = x.name

if srchString.characters.count < truckVIN.characters.count {
    if truckVIN.uppercaseString.containsString(srchString.uppercaseString) {
         repeatFilTrucks.append(item)
    }
}

Case where both if's should = true

T. Steele
  • 325
  • 3
  • 14
  • 3
    Unwrap the optional string before comparing it. http://stackoverflow.com/questions/24034483/what-is-an-unwrapped-value-in-swift – JAL May 31 '16 at 14:13
  • @jal When I insert an "!" after x.name, it tells me that I "Cannot force unwrap value of non-optional type 'String'" – T. Steele May 31 '16 at 14:24
  • Found the issue elsewhere in my code, you were right @Jal. Thanks! – T. Steele May 31 '16 at 14:28
  • Optional are one of the fundamentals of Swift. I *strongly* recommend you read through the introductory docs: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html – Alexander May 31 '16 at 14:30

0 Answers0