title | permalink | layout | excerpt | comments |
---|---|---|---|---|
Notes |
/notes/ |
page |
Catatan Public agar enggak usah pusing-pusing mengingat. |
false |
let vc = UIViewController()
let topVC = sequence(first: vc, next: { $0.presentedViewController }).reversed().first
Reading a file into an array of lines is not possible through an easy built-in like in other languages but we can create something short that doesn't need a for using a combination of split
and map
:
let path = NSBundle.mainBundle().pathForResource("test", ofType: "txt")
let lines = try? String(contentsOfFile: path!).characters.split{$0 == "\n"}.map(String.init)
if let lines=lines {
lines[0] // O! for a Muse of fire, that would ascend
lines[1] // The brightest heaven of invention!
lines[2] // A kingdom for a stage, princes to act
lines[3] // And monarchs to behold the swelling scene.
}