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 trialLinh Nguyen
Courses Plus Student 984 Points.toInt() is longer available and it's driving me insane
In the newest version of Swift, we no longer have the .toInt() method. The only way is to initialize Integer using constructor:
if let culprit = Int(findApt("102")?)
Then I get the error message:
"value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?"
So it suggested that I change the code to:
if let culprit = Int((findApt("102")?)!)
Even then, there's another error message that reads:
"optional chain has no effect, expression already produces 'String?'"
I can delete the Optional(?) and it will be okay as long as findApt() doesn't return a nil value.
What can I do to go around this?
1 Answer
Scott Baumbich
Courses Plus Student 22,129 PointsSo here is the solution that managed to work for me. Still trying to figure out a way to minimize the "if-let" statements. Hope this helps for the time being
if let culprit = findApt("101"){
if let aptNumber = Int(culprit){
sendNoticeTo(aptNumber)
}
}
Linh Nguyen
Courses Plus Student 984 PointsThanks Scott, that made a lot of sense!
Scott Baumbich
Courses Plus Student 22,129 PointsScott Baumbich
Courses Plus Student 22,129 PointsLinh,
Im Having the same problem, if I figure it out or find a solution link i'll post it as a reference.