John
John

Reputation: 1773

Swift on Ubuntu: use of undeclared type 'NSFileHandle'

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

Answers (1)

Martin R
Martin R

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 throwing Swift errors instead of NSExceptions).

Upvotes: 1

Related Questions