Tuesday 15 May 2018

Read data from textfile in swift 3


let path = Bundle.main.path(forResource: "textfile", ofType: "txt")
 print(path!)
                
let url = URL(fileURLWithPath: path!)
 print(url)
                
 let contentString:String = try! String(contentsOf: url, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))

//if convert to Data

 let data = contentString.data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue), allowLossyConversion: false)!
                        

print("string\(contentString)")


No comments:

Post a Comment

Remove bottom line in navigation bar

navigationController ?. navigationBar . setBackgroundImage ( UIImage (), for: . any , barMetrics: . default )          navigat...