Reputation: 1773
am running swift 3.0.2 on Ubuntu.
when I run the following code
import Foundation
let file: NSFileHandle? = NSFileHandle(forReadingAtPath: "data.txt")
I get an error of
test.swift:274:11: error: use of undeclared type 'NSFileHandle' let file: NSFileHandle? = NSFileHandle(forReadingAtPath: "data.txt")
NSFileHandle is in the APIs for Foundation though is this true for the Foundation library on Linux?
What am I doing wrong?
Regards,
Upvotes: 1
Views: 321
Reputation: 539745
From SE-0086 Drop NS Prefix in Swift Foundation:
As part of Swift 3 API Naming and the introduction of Swift Core Libraries, we are dropping the NS prefix from key Foundation types in Swift.
NSFileHandle
is in that list and is called FileHandle
in Swift 3:
import Foundation
let file = FileHandle(forReadingAtPath: "data.txt")
This applies to the Apple platforms and to Linux. The Linux implementation can be seen here: NSFileHandle.swift.
There is a discussion [swift-evolution] Pitch: Replacement for FileHandle
about undoing the renaming and implementing FileHandle
in a more
Swift-like manner (such as throw
ing Swift errors instead of
NSException
s).
Upvotes: 1