Skip to content

Commit 0e59573

Browse files
committed
Create swiftANDInput
Finding the swift equivalent of Python's raw_input("...")/ input("...")
1 parent ce0837e commit 0e59573

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

swiftANDInput

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// PracticeInput.swift
3+
//
4+
//
5+
// Jessica Joseph on 4/1/15.
6+
//
7+
//
8+
9+
import Foundation
10+
11+
func input() -> String{
12+
var keyboard = NSFileHandle.fileHandleWithStandardInput()
13+
var inputData = keyboard.availableData
14+
return NSString(data: inputData, encoding: NSUTF8StringEncoding)! //Swift requires a ('!' OR '?') at the end
15+
16+
// Why is NSString considered to be an optional value?
17+
// What does it mean when an optional type is not unwrapped?
18+
// Why would I need to add the ('!' OR '?') at the end of the return statement?
19+
20+
//ALSO, Since this function takes no parameter, how could I actually use it?
21+
}
22+
23+
24+
// Python 2.7 has the raw_input("..") BIF(built in function) and Python 3 has the input("...") BIF
25+
// What is the swift equivalent? As of right now it seems like there isn't any equivalent
26+
// Is Apple planning on adding a swift equivalent of raw_input() or input()?

0 commit comments

Comments
 (0)