Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Init in Swift language

I read that

init

in Swift does not return value, then why i can write this :

var str = String.init("mystring")
like image 659
tproger Avatar asked Apr 07 '26 06:04

tproger


1 Answers

The function init doesn't return you are right, but in this case, you are just making a variable equal the struct String which is initialised with "hello"

It is the same as:

var class = someClass()

The () is an init function with no arguments.

like image 63
Olivier Wilkinson Avatar answered Apr 10 '26 00:04

Olivier Wilkinson