python - Pythonic way of reading text file using Swift -
i know python , i'm trying learn swift... trying figure out how read plain text file absolute file path
in python,
#!/usr/bin/python path= '/users/mu/desktop/test_file.txt' in_file= open(path,'w').read() #open file reading line in in_file.split('\n'): #split line breaks , print lines print line
tried one: swift - read files got: "string.type not have member name stringwithcontentsoffile"
in python, it's easy. there must simple way read text file , create list of strings separated line breaks.
my question how read text file can iterate through lines
once read file, just:
for line in in_file { println(line) }
you can use nsfilemanager , nsstring parse lines eg :
var path = "somepath" let filemanager = nsfilemanager.defaultmanager() let data:nsdata = filemanager.contentsatpath(path)! var strs = nsstring(data: data, encoding: nsutf8stringencoding)
Comments
Post a Comment