[swift-users] Regression in Xcode8-beta6 Swift?

David Hart david at hartbit.com
Thu Aug 25 03:40:03 CDT 2016


I misunderstood the release notes for Xcode 8 beta 6 I read a few days ago. Here what will interest you:

Since ‘id’ now imports as ‘Any’ rather than ‘AnyObject’, you may see errors where you were previously performing dynamic lookup on ‘AnyObject’. For example in:

      guard let fileEnumerator = FileManager.default.enumerator(atPath: path)
      else {
return }

      for fileName in fileEnumerator {
          if fileName.hasSuffix(".txt") {
              // error: value of type ‘Element’ (aka ‘Any’) has no member
      hasSuffix
              print(fileName)
          }
}
The fix is to either cast to AnyObject explicitly before doing the dynamic lookup, or force cast to a

specific object type:

      guard let fileEnumerator = FileManager.default.enumerator(atPath: path)
      else {
return }

      for fileName in fileEnumerator {
          if (fileName as AnyObject).hasSuffix(".txt") {
              // cast to AnyObject
              print(fileName)
          }
}

(27639935) 



> On 25 Aug 2016, at 10:32, Quinn The Eskimo! via swift-users <swift-users at swift.org> wrote:
> 
> 
> On 25 Aug 2016, at 09:27, David Hart <david at hartbit.com> wrote:
> 
>> That proposal also says:
> 
> Indeed.  Good point.
> 
>> What was decided concerning that?
> 
> I don’t know, although given that that text was from the “Future Directions” section it seems like that nothing has changed yet.
> 
> Share and Enjoy
> --
> Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160825/2fc7f758/attachment.html>


More information about the swift-users mailing list