# What Does Operator _ , ! , ? , ?? Means In Swift

If you are a beginner of iOS swift programming, you may be confused by some strange swift operator, such as _, !, ?, ??. This article will tell you what dose those strange swift operator means one by one.

1. _ : The under score operator is usually used in swift function definition. It is used to replace the function parameter’s external label. So when you call the swift function, you do not need to use function parameter ‘s external label name to specify which parameter this value is assigned to, just pass the parameter in function parameters definition order. You can read article iOS Swift Function External And Internal Parameter Name Example to learn more.
2. ? : The question mark operator is used to define a swift variable as optional variable, which means this variable do not need to be initialized when define it. If do not initialize it with a default value, then it’s default value is nil which is similar with null in java. If the optional variable has child optional variable, then you can use optional chaining to refer it such as a?.b?.c?.text
3. ! : If you want to get an optional variable’s original value, you should add ! mark at the variable name’s end to force unwrap it, then you can use it’s original value. Please read article How To Fix Error ‘Value Of Optional Type Must Be Unwrapped To A Value Of Type’ In Swift to learn more.
4. ?? :  This operator is called nil coalescing operator. It is used to return first none nil value of the two swift variables. For example, for swift code `let z = x ?? y` , if x’s value is not nil then assign x’s value to z, otherwise it will assign y’s value to z. So `let z = x ?? y` can be treated as `let z = x != nil ? x! : y`. Below is a code example.
```// If set x to nil, then the variable z's value is 1
let x:Int? = nil

//let x:Int? = 2

let y:Int = 1

let z = x ?? y

print(z)```
READ :   How To Create iOS Project With XIB File In Xcode

This site uses Akismet to reduce spam. Learn how your comment data is processed.
{"ft_lang_label":"__label__en","ft_lang_prob":0.72222346,"math_prob":0.91583633,"size":1832,"snap":"2020-34-2020-40","text_gpt3_token_len":425,"char_repetition_ratio":0.13621444,"word_repetition_ratio":0.014124294,"special_character_ratio":0.24945416,"punctuation_ratio":0.15931372,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96104014,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-09-27T07:23:29Z\",\"WARC-Record-ID\":\"<urn:uuid:28584325-e9bd-4f67-9c21-b6fcba3bbb51>\",\"Content-Length\":\"99365\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6e44a192-37bd-4807-ad1e-090f990c1cd5>\",\"WARC-Concurrent-To\":\"<urn:uuid:1f58cf0a-47d7-40d9-a828-90ee0700672a>\",\"WARC-IP-Address\":\"104.27.146.13\",\"WARC-Target-URI\":\"https://www.dev2qa.com/what-does-operator-_-means-in-swift/\",\"WARC-Payload-Digest\":\"sha1:AAVBMABHFO5FV52QIPMUYHTQB4TFTCQZ\",\"WARC-Block-Digest\":\"sha1:XJLRT4CW7TXBYHSOMFPR7IUOGSK6B7QD\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-40/CC-MAIN-2020-40_segments_1600400265461.58_warc_CC-MAIN-20200927054550-20200927084550-00577.warc.gz\"}"}