ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • In-Out Parameters - Functions
    iOS/๐ŸŸ  Swift 2020. 11. 6. 16:04

    "์ž…์ถœ๋ ฅ ํŒŒ๋ผ๋ฏธํ„ฐ"

     

    ํ•จ์ˆ˜ Argument์— ๊ฐ’ ์ „๋‹ฌ ์‹œ, Parameter๋Š” ์ž„์‹œ ์ƒ์ˆ˜๋กœ์„œ ๊ฐ’์„ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค. ( immutable )

     

    ์‹ค์ œ๋กœ ์ „๋‹ฌํ•œ Argument์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ์„ ๋•Œ, inout์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

    c++์˜ ์ฐธ์กฐ์ž์™€ ๋น„์Šทํ•œ ๊ธฐ๋Šฅ์„ ํ•ฉ๋‹ˆ๋‹ค.

     

    /* ์ •์˜๋ถ€ */
    func example(name: inout Type) {
    	...
    }
    
    /* ํ˜ธ์ถœ๋ถ€ */
    example(name: &expr)    //์ „๋‹ฌํ•  ๊ฐ’์— &๋ฅผ ๋ถ™์—ฌ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.

     

    ์ฃผ์˜ํ•  ์ 

    1. ๋ฆฌํ„ฐ๋Ÿด์„ ์ „๋‹ฌํ•˜๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.

    ๋ฆฌํ„ฐ๋Ÿด์€ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์ด ๋”ฐ๋กœ ์—†์Šต๋‹ˆ๋‹ค.

    2. ์ƒ์ˆ˜๋ฅผ ์ „๋‹ฌํ•˜๋ฉด ์•ˆ ๋ฉ๋‹ˆ๋‹ค.

    immutable์ž…๋‹ˆ๋‹ค.

    3. ๊ฐ€๋ณ€ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ „๋‹ฌํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

     

    4. ๊ธฐ๋ณธ ๊ฐ’์„ ์ง€์ •ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

     

    'iOS > ๐ŸŸ  Swift' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

    Variadic Parameters - Functions  (0) 2020.11.07
    Argument Label - Functions  (0) 2020.11.07
    Parameters - Functions  (0) 2020.11.06
    guard Statement - Conditional Statements  (0) 2020.11.04
    Type Safety - Data Types  (0) 2020.11.03

    ๋Œ“๊ธ€

์–ด์ œ๋ณด๋‹ค ๋ฐœ์ „ํ•œ ๋‚˜