VesselWheel

argument label 본문

Xcode Study

argument label

JasonYang 2023. 10. 14. 07:45

import UIKit

 

// argument label

// (name: String)

// (to name: String)

// name : parameter 이름

// to   : argument label

 

func sayHello(name: String){

    print("Hello, \(name)")

}

sayHello(name: "더조은")

 

// 함수의 이름과 parameter 이름, 개수, type이

// 같으나, 중복 오류가 발생하지 않음

//  ㄴ argument label 을 사용했기 때문

func sayHello(to name: String){

    // 함수 body에서는 argument label 사용 못함

    // print("Hello, \(to)")

    print("Hello, \(name)")

}

 

func sayHello2(to name: String){

    // 함수 body에서는 argument label 사용 못함

    // print("Hello, \(to)")

    print("Hello, \(name)")

}

// parameter 를 선언할 때 argument label 을

// 작성해 놓으면 호출할 때, parameter 이름을

// 사용할 수 없음

// sayHello2(name: "이순신")

// 함수를 호출할 때는 argument label 을 사용함

sayHello2(to: "이순신")

sayHello2(to: "유관순")

 

// argument label 에 wildcard pattern 사용하기

func sayHello(_ name: String){

    print("Hello, \(name)")

}

sayHello(_: "양만춘")

sayHello("장보고")

// 9 행에 있는 sayHello() 가 호출됨

sayHello(name: "이율곡")

 

// 함수이름 : 동사

// parameter 이름 : 명사

// argument label : 전치사

 

 

 

'Xcode Study' 카테고리의 다른 글

In-Out paramters// 입출력 파라미터  (0) 2023.10.14
가변 parameters(variadic parameters) / 4-4  (1) 2023.10.14
parameter 가 있는 함수  (0) 2023.10.14
Function (함수)  (1) 2023.10.14
Optional Pattern  (0) 2023.10.14