When I try to use a filter to restrict the files I am looking at in a directory using
let InputDir = try! FileManager.defaultManager.contentsOfDirectory(atPath: tPath.stringValue)
let txtFiles = InputDir.filter( $0.pathExtension == “txt”)
I get the error ‘No anonymous method is in scope’ with $0 on the second line highlighted
This works fine in native Swift, is the syntax different in Silver?
mh
(marc hoffman)
2
i believe this needs curly braces, no?
let txtFiles = InputDir.filter({ $0.pathExtension == “txt” })
peter1
(Peter Lusmore)
3
Unfortunately, that gives the error ‘No matching overload’ with .filter highlighted
mh
(marc hoffman)
4
Hmm, let me see… What platform, .NET?
mh
(marc hoffman)
5
Reproduced. this looks like a big, since finter is defined as
public func filter(_ includeElement: (_ param0: id) -> Bool throws<T>!, error $error: inout NSError!) -> ISequence<T>
mh
(marc hoffman)
6
E25476, sorry. somehow the post-back from the bugdb didn’t go thru; my mistake.
peter1
(Peter Lusmore)
7
Can you let me know when it makes its way into a released version?
mh
(marc hoffman)
8
I’ve updated/fixed the issue so that updates should be posted here; once it’s marked as fixed, it will be in the following Friday’s build.
mh
(marc hoffman)
9
Meanwhile, if a bit cumbersome, filter()
does work on [T]
, so of you cast the NSArray to [NSString]
, it does compile:
let txtFiles = (InputDir as! [NSString]).filter( {$0.pathExtension == "txt"} )
bugs://E25476 was closed as fixed.