So I am trying to make a text-based game, but I cannot find out in the ibook about Swift made by apple how to get input from the console. I have tried a few ways that I saw on here, but I did not really understand how to use those methods.
Asked
Active
Viewed 6,651 times
1
-
1Before you release this text-based game you will have to find some other way for the user to input text. There is no console on the devices. – 67cherries Jun 05 '14 at 13:56
-
What exactly do you mean by Console ? – A-Live Jun 05 '14 at 14:10
-
2@68cherries You can use Swift to build Mac applications too. OS X has a terminal. – aapierce Jun 05 '14 at 14:45
-
In fact, Xcode provides for OSX command-line (console) apps using swift. Not interactively, but it does allow for them. – aramis Aug 19 '15 at 01:09
1 Answers
-1
It doesn't look like there are any input stream facilities in the Swift standard library. But you still have options:
import Darwin
and usescanf
orgetc
or your favorite POSIX level input routineimport Foundation
and useNSInputStream
,NSScanner
etc.

rickster
- 124,678
- 26
- 272
- 326
-
1Unfortunately, only a subset of Darwin is working right now like rand(). – Chad Brewbaker Jun 05 '14 at 18:09
-
Please come up with a working example to best solve the askers question. – Timothy Swan Aug 20 '15 at 14:51