(editied to show Swift 1 and Swift 2 code)
I'm trying to read a small text file using Swift 2.2 on Linux (December 22 snapshot).
Mint 14.04 and Ubuntu 15.10 produce identical results.
If there is any way to read from a text file, please answer.
Swift 2 source:
let text = String.stringWithContentsOfFile(path, encoding: NSUTF8StringEncoding, error: nil) print(text) error:
prefix.swift:18:13: error: type 'String' has no member 'stringWithContentsOfFile' let text = String.stringWithContentsOfFile(path, encoding: NSUTF8StringEncoding, error: nil) ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~ Swift 1 source:
import Foundation let text = NSString(contentsOfFile: "foo.txt", encoding: NSASCIIStringEncoding, error: nil) print(text) error:
prefix.swift:14:12: error: argument labels '(contentsOfFile:, encoding:, error:)' do not match any available overloads let text = NSString(contentsOfFile: "foo.txt", encoding: NSASCIIStringEncoding, error: nil) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ prefix.swift:14:12: note: overloads for 'NSString' exist with these partially matching parameter lists: (charactersNoCopy: UnsafeMutablePointer<unichar>, length: Int, freeWhenDone: Bool), (format: String, locale: AnyObject?, arguments: CVaListPointer), (bytes: UnsafePointer<Void>, length: Int, encoding: UInt) var text = NSString(contentsOfFile: "foo.txt", encoding: NSASCIIStringEncoding, error: nil) ^