Swift에서 commandLine 입력받기
처음부터 찬찬히 다시 언어를 짚어가며 공부하다가 왜 Swift 에서는 stdin같은
표준 키보드 입력이 없을까 찾아보았다.
물론 없지는 않았다. 하지만 Swift 로 구현하는 결과물은 GUI 가 있으므로(ex 텍스트박스, 필드)
굳이 키보드 입력이 필요한가 싶기도 하다. 그렇지만 입력예제는 아래와 같다.
let response = readLine(stripNewline: true)
print(response) //출력결과: optional("입력한 값")
참고자료
http://stackoverflow.com/questions/24004776/input-from-the-keyboard-in-command-line-applicationhttp://stackoverflow.com/questions/24155012/what-is-cin-in-c-command-in-swift
https://teamtreehouse.com/community/do-swift-have-a-function-to-understand-input-from-keyboard-and-implement-it-to-variable-like-cin-in-c-language
'IOS > Swift' 카테고리의 다른 글
함수의 반환 타입으로 함수 사용 (0) | 2016.05.07 |
---|---|
인자값과 반환값 (0) | 2016.05.07 |
일급 함수란? (0) | 2016.05.07 |
inout 키워드 매개변수 외부 전달 (0) | 2016.05.07 |
Swift 3.0 대비 Deprecated (0) | 2016.05.07 |
댓글 로드 중…
트랙백을 확인할 수 있습니다
URL을 배껴둬서 트랙백을 보낼 수 있습니다