ios - Will optional values be de-initialized automatically? -


i new swift, please ignore if asking dumb questions ;)

is required explicitly set optional values nil, if not needed more? how weak, strong reference works in swift? if normal variables has de-initialized manually? since there no way assign nil normal variables in swift, please let me know how it. difference between?

var somevar:string? vs var somevar:string! 

i see difference in accessing them. first prints values within optional , second doesn't , second throws exception when value nil. difference?

is required explicitly set optional values nil

no, automatic reference counting frees memory automatically. unless there circular reference, e.g., there strong reference classa in classb , vice-versa. also, automatic reference counting applies instances of classes , not value types (string, int, enum, etc). memory of these value types freed when parent instances deinitialized.

is difference?

var somevar:string! creates implicitly unwrapped optional, optional automatically unwrapped when accessed. accessing implicitly unwrapped optional when it's nil causes runtime error.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -