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
Erico Souza Mendes
3,732 PointsSwift 2 Optionals and ToInt()
Hello guys
I'm doing the second video class of optionals and trying Amit code on my Xcode.
Currently, I'm using Xcode 7 with Swift 2 So my code are like this:
func sendNoticeTo(aptNumber aptNumber: Int) {
}
func findApt (aptNumber: String) -> String? {
let aptNumbers = ["101", "202", "303", "404"]
for tempAptNumbers in aptNumbers {
if (tempAptNumbers == aptNumber) {
return aptNumber
}
}
return nil
}
if let culprit = findApt("101")?.ToInt() {
sendNoticeTo(aptNumber: culprit)
}
<p>But the problem is that the (?.toInt()) doesn't work anymore on Swift2 </p> Error: 'String' does not have a member named 'ToInt'
There's a way to make this To Int conversion and it still accept nil results?
1 Answer
Avi Zolty
2,001 PointstoInt() not ToInt :)