# User input code using Swift 3

**URL:** <https://forums.kodeco.com/t/user-input-code-using-swift-3/19001>\
**Category:** Swift\
**Created:** [August 26, 2016, 10:42pm UTC](https://forums.kodeco.com/t/user-input-code-using-swift-3/19001 "2016-08-26T22:42:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![elearner](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/elearner/32/109248_2.png) [@elearner](https://forums.kodeco.com/u/elearner)\
**Post date:** [August 26, 2016, 10:42pm UTC](https://forums.kodeco.com/t/user-input-code-using-swift-3/19001/1 "2016-08-26T22:42:09Z")

</div>

Continuing the discussion from [Learn to Code iOS Apps with Swift Tutorial 2: Your First Project](https://forums.kodeco.com/t/learn-to-code-ios-apps-with-swift-tutorial-2-your-first-project/6673):

Brian,

I’ve downloaded Xcode 8 beta 6 trying to learn Swift 3.

I was trying to use your Swift beginner code but need some help with the Swift 3 changes  
for the guessing game that takes keyboard input or user input. The current code doesn’t work in Swift 3.  
I realized that I’m running a beta version of Xcode and that any code you give me now may change again  
but that’s ok. I just want to get it working at this time.

Here’s the current code that I’m talking about:

func input() → String {  
let keyboard = NSFileHandle.fileHandleWithStandardInput()  
let inputData = keyboard.availableData  
let rawString = NSString(data: inputData, encoding:NSUTF8StringEncoding)  
if let string = rawString {  
return string.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())  
} else {  
return “Invalid input”  
}  
}

Thanks for your help in advance!  
Gary

---

<div class="post-metadata">

**Author:** ![marciokoko](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/marciokoko/32/32922_2.png) [@marciokoko](https://forums.kodeco.com/u/marciokoko)\
**Post date:** [August 30, 2016, 4:03pm UTC](https://forums.kodeco.com/t/user-input-code-using-swift-3/19001/2 "2016-08-30T16:03:39Z")

</div>

What seems to be the problem? What errors does xcode give you?

---

<div class="post-metadata">

**Author:** ![vegetarianzombie](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/vegetarianzombie/32/94022_2.png) [@vegetarianzombie](https://forums.kodeco.com/u/vegetarianzombie)\
**Post date:** [August 31, 2016, 6:36pm UTC](https://forums.kodeco.com/t/user-input-code-using-swift-3/19001/3 "2016-08-31T18:36:54Z")

</div>

I haven’t run the code in the latest version of Xcode, but I wouldn’t be surprised if it was broken. We’ll be updating the tutorial pretty soon.

---

<div class="post-metadata">

**Author:** ![elearner](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/elearner/32/109248_2.png) [@elearner](https://forums.kodeco.com/u/elearner)\
**Post date:** [September 1, 2016, 9:24pm UTC](https://forums.kodeco.com/t/user-input-code-using-swift-3/19001/4 "2016-09-01T21:24:48Z")

</div>

Thanks for your reply.  
Xcode 8 should be released soon. I’m looking forward to the tutorial updates but will work  
with learning Swift 2.2 for now.

Gary

---

<div class="post-metadata">

**Author:** ![elearner](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/elearner/32/109248_2.png) [@elearner](https://forums.kodeco.com/u/elearner)\
**Post date:** [September 4, 2016, 3:27am UTC](https://forums.kodeco.com/t/user-input-code-using-swift-3/19001/5 "2016-09-04T03:27:31Z")

</div>

Sorry, I couldn’t tell you now. There were several error messages. In the interim, I’ve backed out of  
Xcode 8 Beta 6 using Swift 3 and have dropped back to Swift 2.2 where all the tutorial code is  
working fine.

I assume Apple will be releasing Xcode 8 either this next Wed the 7th or sometime later this month.  
I’ll wait until the final version of Xcode 8 is released before I start using Swift 3 , again.

I know all the tutorials will be updated to Swift 3 sometime soon so I won’t encounter those  
previous problems that I was having using Xcode 8 Beta 6.

Thanks for your response!

Gary

---

<div class="post-metadata">

**Author:** ![marciokoko](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/marciokoko/32/32922_2.png) [@marciokoko](https://forums.kodeco.com/u/marciokoko)\
**Post date:** [September 4, 2016, 3:43pm UTC](https://forums.kodeco.com/t/user-input-code-using-swift-3/19001/6 "2016-09-04T15:43:11Z")

</div>

OK. Next time feel free to throw up all errors and we can help you sort them out one by one.

---

<div class="post-metadata">

**Author:** ![elearner](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/elearner/32/109248_2.png) [@elearner](https://forums.kodeco.com/u/elearner)\
**Post date:** [September 4, 2016, 10:00pm UTC](https://forums.kodeco.com/t/user-input-code-using-swift-3/19001/7 "2016-09-04T22:00:06Z")

</div>

Thanks Marcio. I appreciate it!

Gary
