(edited to display Swift 1 and Swift 2 code)
I am trying to read a small text file using Swift 2.2 on Linux (snapshot December 22).
Mint 14.04 and Ubuntu 15.10 give identical results.
If there is any way to read from a text file, respond.
Swift 2 Source:
let text = String.stringWithContentsOfFile(path, encoding: NSUTF8StringEncoding, error: nil)
print(text)
Mistake:
prefix.swift:18:13: error: type 'String' has no member 'stringWithContentsOfFile'
let text = String.stringWithContentsOfFile(path, encoding: NSUTF8StringEncoding, error: nil)
^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
Source Swift 1:
import Foundation
let text = NSString(contentsOfFile: "foo.txt", encoding: NSASCIIStringEncoding, error: nil)
print(text)
Mistake:
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)
^
source
share