Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Functions and Optionals Optionals Optional Chaining

George Hawkins
George Hawkins
4,269 Points

How to convert from String to Int in code 8

Hello, I am using Xcode 8 and I understand that these tutorials use an earlier version.

The .toInt() function no longer works as described in the video. What are my other options for achieving this? Below is what I have so far.

import UIKit

func findApt (aptNumber:String) -> String? { let aptNumbers = ["101", "202", "303", "404"] for tempAptNumber in aptNumbers { if tempAptNumber == aptNumber { return aptNumber } } return nil }

func sendNoticeTo (aptNumber:Int) {

}

if let culprit = findApt(aptNumber:"101") { sendNoticeTo(aptNumber: culprit) }

1 Answer

Bjorn Morrhaye
Bjorn Morrhaye
2,387 Points
var stringNumber = "1234"
var numberFromString = Int(stringNumber)