Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inferred to have type 'AnyClass', which may be unexpected

Tags:

swift

Here is my code:

if let runningTests = NSClassFromString("XCTestCase") {
    return false
}

The compiler warning:

"Constant 'runningTests' inferred to have type 'AnyClass', which may be unexpected.

What is it I need to cast to to remove this warning without changing my code into a if != nil check on the result of NSClassFromString?

like image 762
bandejapaisa Avatar asked Feb 12 '23 19:02

bandejapaisa


1 Answers

You actually mean AnyClass here, so you just need to tell the compiler that:

if let runningTests: AnyClass = NSClassFromString("XCTestCase") {
    return false
}
like image 65
Rob Napier Avatar answered Mar 12 '23 14:03

Rob Napier