Reading from Standard In


(Kyle Bashour) #1

Hi Everyone,

I hope this is the best place to discuss this — if not, please point me in
the right direction! It seems like an appropriate topic for evolution
though.

According to my limited knowledge and basic research, Swift doesn't
currently have a simple way to read from standard input from the console.
The best solution I found was this StackOverflow solution
<http://stackoverflow.com/questions/24046952/xcode-6-swift-read-standard-input-console-to-string>,
but it doesn't seem to be implemented on Linux yet, and I think it should
be simpler than having to use NSFileHandle if Swift is to be used as a true
systems programming language.

Of course, if there is an easier way to do this, please let me know! Or a
reason why the SO solution is the best way to do this. Thanks for reading,
would love to hear thoughts on this. I also just joined the list, so if
this has already been discussed, apologies.

-- Kyle Bashour

@kylebshr
kylebashour.com


(Austin Zheng) #2

Does the 'readline' function (introduced in Swift 2.x) work for your purposes? http://swiftdoc.org/v2.1/func/readLine/

Austin

···

On Dec 6, 2015, at 9:19 PM, Kyle Bashour via swift-evolution <swift-evolution@swift.org> wrote:

Hi Everyone,

I hope this is the best place to discuss this — if not, please point me in the right direction! It seems like an appropriate topic for evolution though.

According to my limited knowledge and basic research, Swift doesn't currently have a simple way to read from standard input from the console. The best solution I found was this StackOverflow solution <http://stackoverflow.com/questions/24046952/xcode-6-swift-read-standard-input-console-to-string>, but it doesn't seem to be implemented on Linux yet, and I think it should be simpler than having to use NSFileHandle if Swift is to be used as a true systems programming language.

Of course, if there is an easier way to do this, please let me know! Or a reason why the SO solution is the best way to do this. Thanks for reading, would love to hear thoughts on this. I also just joined the list, so if this has already been discussed, apologies.

-- Kyle Bashour

@kylebshr
kylebashour.com <http://kylebashour.com/> _______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution