ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Variadic Parameters - Functions
    iOS/๐ŸŸ  Swift 2020. 11. 7. 16:54

    "๊ฐ€๋ณ€ ํŒŒ๋ผ๋ฏธํ„ฐ"

    func example(name: Type...) {
    	...
    }

     

    ํ•˜๋‚˜์˜ Parameter์— ๊ฐ™์€ ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ๊ฐ€์ง„ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ฐ’์„ Argument๋กœ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    ์˜ˆ๋ฅผ ๋“ค์–ด, print(_:seperator:terminator:) ๋ฅผ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

     

    /* print(_:seperator:terminator:)์˜ prototype */
    
    public func print(_ items: Any..., separator: String = " ", terminator: String = "\n")

     

    ์ฒซ ๋ฒˆ์งธ Parameter๋ฅผ Variadic Parameters๋กœ ์„ ์–ธํ•˜์˜€์Šต๋‹ˆ๋‹ค.

    Any... ์ด๋ฏ€๋กœ , ์–ด๋–ค ํƒ€์ž…์ด๋“  ๊ฐœ์ˆ˜์— ์ƒ๊ด€์—†์ด ๋„ฃ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

     

    Variadic Parameter์˜ ์ œ์•ฝ์‚ฌํ•ญ

        1. ํ•จ์ˆ˜ ํ•˜๋‚˜๋‹น ํ•˜๋‚˜์˜ Variadic Parameter๋ฅผ ์„ ์–ธํ•  ์ˆ˜ ์žˆ๋‹ค.

        2. ๊ธฐ๋ณธ ๊ฐ’์„ ์„ค์ •ํ•  ์ˆ˜ ์—†๋‹ค.

        3. ์„ ์–ธ ์ˆœ์„œ๋Š” ์ƒ๊ด€์—†๋‹ค. ๋‘๋ฒˆ์งธ Parameter์ด๋“  ์„ธ ๋ฒˆ์งธ์ด๋“  ์ƒ๊ด€์—†๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค.

     

     

     

    ๋.


     

    ์ด์ „ ๊ธ€: Argument Label - Functions

     

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

    Function Types - Functions  (0) 2020.11.08
    [Swift] Function Notation - Functions  (2) 2020.11.08
    Argument Label - Functions  (0) 2020.11.07
    In-Out Parameters - Functions  (0) 2020.11.06
    Parameters - Functions  (0) 2020.11.06

    ๋Œ“๊ธ€

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