Read complete story

Use of typealias in Swift

Hello Guys , I hope you all are enjoying mobikul blogs.

In today’s blog we will write a small program about the use of typealias in swift.

Now the first thing is “What is typealias and how to use it in our programming?”. Your answer is written below.

Typealias – A type alias declaration introduces a named alias of an existing type into your program. Type alias declarations are declared using the keyword typealias and have the following form:

typealias name = existing type

eg. typealias myDataType = String

ok , lets start by understanding the following code.

Alright guys lets dive into the code and learn whats happening here.

typealias test = (Bool?) -> Void

Created a test named typealias of type (Bool?)->Void

typealias stringType = String

Created a stringType named typealias of type String

The above function will take test type parameter and will call it.

The function callvalueFalse will take two parameters of type test and stringType and will call the test after 3 seconds.

the @escaping keyword represents that our closure will escape the function means first the function will complete and on its completion the closure will get executed.

now inside our button action we called the functions.

self.valueLabel.text = “false”

the false text is assigned to label after 3 seconds because the callvalueFalse functions closure will get executed after 3 seconds.

i.e why we declared escaping there.

Thats enough guys If you have any confusion please comment below.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close