5์ผ์ฐจ: 100DaysOfSwift๐Ÿš€

1692 ๋‹จ์–ด swiftios100daysofcodeswiftui

5์ผ์ฐจ



๊ธฐ๋Šฅ



ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ฝ”๋“œ๋ฅผ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฆ‰, ํฅ๋ฏธ๋กœ์šด ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•˜๊ณ  ์—ฌ๋Ÿฌ ๊ณณ์—์„œ ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ฝ”๋“œ๋ฅผ ๋ฐ˜๋ณตํ•˜๋Š” ๊ฒƒ์€ ์ผ๋ฐ˜์ ์œผ๋กœ ๋‚˜์œ ์ƒ๊ฐ์ด๋ฉฐ, ํ•จ์ˆ˜๋Š” ์šฐ๋ฆฌ๊ฐ€ ๊ทธ๋ ‡๊ฒŒ ํ•˜์ง€ ์•Š๋„๋ก ๋„์™€์ค๋‹ˆ๋‹ค.

func printHelp() {
    let message = "Namste Swift"

    print(message)
} 




๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ์‹คํ–‰

printHelp()
//output: Namste Swift



1. ๋งค๊ฐœ๋ณ€์ˆ˜ ์ˆ˜๋ฝ



์ด๋Ÿฐ ์‹์œผ๋กœ ํ•จ์ˆ˜๋กœ ์ „์†ก๋˜๋Š” ๊ฐ’์„ ๋งค๊ฐœ๋ณ€์ˆ˜๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

func sauChavan(Parameter: DataType){
//code
}

sauChavan(Parameter: argument)






func sauChavan(Surname:String){
    let name="saurabh \(Surname)"
    print(name)
}

sauChavan(Surname:"Chavan")
//Output: saurabh chavan


2. ๋ฐ˜ํ™˜ ๊ฐ’




func square(number: Int) -> Int {
    return number * number
}

let result = square(number: 8)
print(result)


3. ๋งค๊ฐœ๋ณ€์ˆ˜ ๋ผ๋ฒจ




func sayHello(to name: String) {
    print("Hello, \(name)!")
}

sayHello(to: "Saurabh")
//output: Hello Saurabh


4. ํŒŒ๋ผ๋ฏธํ„ฐ ๋ผ๋ฒจ ์ƒ๋žต




func Hello(_ person: String) {
    print("Hello, \(person)!")
}
Hello("Saurabh")
//output: Hello Saurabh


์—ฌ๊ธฐ์—์„œ ๊ฐ€์žฅ ์ข‹์€ ๋ฐฉ๋ฒ•๊ณผ ์‰ฌ์šด ๋ฐฉ๋ฒ•Function์„ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ