Swift: Closure oddity
| Originator: | raise.rescue | ||
| Number: | rdar://18835890 | Date Originated: | 31.10.2014 |
| Status: | Closed in Xcode 7.1b2 | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.1 / 6A1052d |
| Classification: | Other bug | Reproducible: | Always |
Summary:
I'm getting an error from the compiler i can only describe by an example. I'm receiving an array of the type [AnyObject] from a Foundation-method but i know that it only contains strings, and i want to filter these strings by two criteria. The following example outlines that code:
let objects : [AnyObject] = ["1", "2", "3"]
let allFiles = (objects as [String]).filter { $0.pathExtension == "strings" && $0.rangeOfString("findme") == false }
Now I'm getting the error "'AnyObject' is not identical to 'String'", pointing at the [String]-cast. But when i remove the second criteria within the filter-closure, i don't get that error and it works as expected:
let objects : [AnyObject] = ["1", "2", "3"]
let allFiles = (objects as [String]).filter { $0.pathExtension == "strings" }
So, the content of the closure impacts the compilation of the cast? I don't know if it is more related to the closure or the cast, in any case, this is an odd behavior.
Steps to Reproduce:
Expected Results:
Actual Results:
Version:
Xcode 6.1 / 6A1052d
Notes:
Configuration:
Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!