Created
December 21, 2015 10:55
-
-
Save samhann/a20edc0e089e20d399a6 to your computer and use it in GitHub Desktop.
Iterate Directories Using Swift Generators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Skip to content | |
Search… | |
All gists | |
GitHub | |
Sign up for a GitHub account Sign in | |
Create a gist now | |
Instantly share code, notes, and snippets. | |
Delete | |
Star 0 Fork 0 anonymousanonymous/IterateFiles.swift | |
Created just now | |
Embed | |
<script src="https://gist.github.com/anonymous/30b71601a7fc2555e983.js"></script> | |
Download ZIP | |
Code Revisions 1 | |
Iterate directories using swift sequences | |
Raw IterateFiles.swift | |
import Foundation | |
class OS | |
{ | |
static func enumeratePath(let path: String)->AnyGenerator<String> | |
{ | |
let fileManager = NSFileManager.defaultManager() | |
let enumerator:NSDirectoryEnumerator? = fileManager.enumeratorAtPath(path) | |
let genClosure : () -> String? = | |
{ | |
return enumerator?.nextObject() as? String | |
} | |
return anyGenerator(genClosure) | |
} | |
static func homeDirectory()->NSString | |
{ | |
return NSHomeDirectory() | |
} | |
} | |
print(OS.enumeratePath(OS.homeDirectory().stringByAppendingPathComponent("Desktop")).filter({ $0.containsString("swift")})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment