Swift3.0.1で若干変わったIntなどの数値型⇔AnyObjectのcast
Xcode8(Swift3.0.0)だと↓のテストは通るんですが、
import XCTest @testable import TypeTest class TypeTests: XCTestCase { func testType_WhenIntToAnyObject() { let intValue = ["hoge": Int(1) as AnyObject] XCTAssertTrue(intValue["hoge"] is Int) XCTAssertTrue(intValue["hoge"] is Float) XCTAssertTrue(intValue["hoge"] is Double) XCTAssertTrue(intValue["hoge"] is CGFloat) } func testType_WhenCGFloatToAnyObject() { let cgfloatValue = ["hoge": CGFloat(1.0) as AnyObject] XCTAssertTrue(cgfloatValue["hoge"] is Float) XCTAssertTrue(cgfloatalue["hoge"] is Double) XCTAssertTrue(cgfloatValue["hoge"] is CGFloat) } }
Xcode8.1(Swift3.0.1)だと↓のようにAnyObjectにcastする前の型のみ正しく判定されるようになってました
SE-0139によるところかと思われます。 あんまりちゃんと読んでないですが、以下のようなこと書いてあったし。
Bridged NSNumber and NSValue objects must be castable back to their original Swift value types.
雑にAnyObjectをcast backしてる場合はSwfit3.0.1にするとcastに失敗するようになるので注意が必要かもです