NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

Implicit Unwraping

Forums > 100 Days of Swift

Hi Guys,

I am currently on project 7 but I still do not undertsand why in project 4 we implicity uwrapped the webView property.

var = webView: WKWebView!

   

You are declaring that it there and when you come to use it will be there. Same as when you use var button: UIButton!

and then in the override func loadView() you put

webView = WKWebView()

PS no = in the var webView: WKWebView!

1      

Yeah but why do I need to implicitly unwrap it.

   

You need to do that to tell Xcode that you're sure it will be there at runtime. If you leave the ! out, you will see Xcode will complain about not having an initialiser. That;s another option, to initialise the property in an initialiser.

Another option is to directly initialise the property like so:

var webView = WKWebView()

You assign a WKWWebView to the var webView and initialise it on the go!

1      

Okay makes sense, thanks guys!

   

Hacking with Swift is sponsored by Fernando Olivares

SPONSORED Would you describe yourself as knowledgeable, but struggling when you have to come up with your own code? Fernando Olivares has a new book containing iOS rules you can immediately apply to your coding habits to see dramatic improvements, while also teaching applied programming fundamentals seen in refactored code from published apps.

Try the book!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.