DEV Community

Cover image for My first week of learning Swift.

My first week of learning Swift.

Awdesh on September 14, 2018

1.) Declaring constants and variables. Variables Constants: Once declared their value can't be changed. Swift will throw compile time...
Collapse
 
nunovieira profile image
Nuno Vieira • Edited

in 7) What you really should do to print the "name", is unwrapping the optional with Optional Binding (if-let) Example:

if let name = name {
       print(name)
}

With this approach, you don't need to verify first if it is nil and then force unwrap it. (Normally force unwrapping things in swift is a bad practice, unless is Outlets or if you don't have any other option for some kind of reason)

Collapse
 
s_awdesh profile image
Awdesh

Perfect. That's a great input.

I have updated the article now.

Collapse
 
jacobboyd profile image
Jacob Boyd

Great post, it would have been a nice follow up to discuss optional bindings and chaining after your section on optionals!

Collapse
 
s_awdesh profile image
Awdesh

Thanks for the feedback Jocab.

I'll try to read more about the optional chaining and binding and write about it in near future. Although I found Stack Overflow article ( referenced ) very informative.

Collapse
 
tofulosophy profile image
tofulosophy

Nice article!

Collapse
 
remo_vinoth profile image
vinoth

Please post article on handling keyboards with textfields, validating textfields for something and throw error.