Author Topic: Fixing the "Forced cast to same type has no effect" warning  (Read 4608 times)

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
Fixing the "Forced cast to same type has no effect" warning
« on: September 11, 2015, 04:46:53 AM »
The Swift 2.0 compiler now warns you if your code is forcing the cast of an object to the type that it already is.

For example, the following code uses the as! operator to force response.products to an array of SKProduct objects:

Code: [Select]
let validProducts = response.products as! [SKProduct]
However, since response.products is already an array of SKProduct objects, it produces a compiler warning. To get rid of the warning, remove the cast:

Code: [Select]
let validProducts = response.products
All the best!
Kevin McNeish
Author of Learn to Code in Swift: https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11
Check out our Robot Tic-Tac-Toe app: https://itunes.apple.com/us/app/robot-tic-tac-toe/id990638517?mt=8
« Last Edit: November 15, 2015, 10:13:23 AM by kjmcneish »