Swiftlint: Question about force cast violation.

Created on 28 Jan 2016  路  2Comments  路  Source: realm/SwiftLint

Hi, I've started learning Swift recently and have been using the swiftlint rules as a guide for good code practices. Regarding the force_cast error, code like this won't pass swiftlint:

someVar = someOptional as! OtherType

But this does:

someVar = (someOptional as? OtherType)!

Aren't those essentially the same thing? Shouldn't both trigger the force_cast error ?

question

Most helpful comment

No, because technically the second is not a force_cast, it is a force_unwrapping of an optional cast. force_unwrapping is an OptInRule that you can enable using enabled_rules in your configuration file.

All 2 comments

No, because technically the second is not a force_cast, it is a force_unwrapping of an optional cast. force_unwrapping is an OptInRule that you can enable using enabled_rules in your configuration file.

I see, thanks for the help @scottrhoyt

Was this page helpful?
0 / 5 - 0 ratings