read1 [swift] 문자열 읽기/쓰기 Version: Swift 4.2, Xcode 10, iOS 12 Text 문자열에 대한 파일 read/write 시 String 객체의 맴버함수를 사용할 수 있습니다. 파일에서 문자열을 읽어오는 방법 func read(fileUrl: URL) -> String? { var text: String? do { text = try String(contentsOf: fileUrl) } catch { print(error.localizedDescription) } return text } 파일에 문자열을 쓰는 방법 func write(fileUrl: URL, text: String) { do { try text.write(to: fileUrl, atomically: false, encoding: .utf8) }.. 2019. 2. 9. 이전 1 다음