Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- mssql
- 함수
- node.js
- 맛집
- IOS
- javascript
- PER
- 날짜
- 유니티
- 다이어트
- swift
- tensorflow
- pandas
- MySQL
- PyQt5
- flutter
- PyQt
- ubuntu
- Excel
- Linux
- sqlite
- 리눅스
- port
- python
- 라즈베리파이
- GIT
- urllib
- Unity
- MS-SQL
- ASP
Archives
아미(아름다운미소)
[문법요약] 함수 본문
- 함수
//: Playground - noun: a place where people can play import UIKit let name = "BTS" func printName() { print(name) } func printName(userName: String) { print(userName) } //func printName(userName: String) -> Void { // print(userName) //} func printName2(userName: String) -> Int { print(userName) return userName.characters.count } //진 얼앰 슈가 뷔 제이홉 정국 지민 printName() printName(userName: "선동렬") printName2(userName: "진") printName2(userName: "얼앰") printName2(userName: "슈가") printName2(userName: "뷔") printName2(userName: "제이홉") printName2(userName: "정국") printName2(userName: "지민") func sum(lhs: Int, rhs: Int) -> Int { let s = lhs + rhs return s } sum(lhs: 10, rhs: 7) sum(lhs: 20, rhs: 5) func sum2(leftHandSide lhs: Int, rightHandSide rhs: Int) -> Int { let s = lhs + rhs return s } sum2(leftHandSide: 10, rightHandSide: 20) func sum3(_ lhs: Int, rightHandSide rhs: Int) -> Int { let s = lhs + rhs return s } sum3(10, rightHandSide: 10) func sum4(_ lhs: Int, _ rhs: Int) -> Int { let s = lhs + rhs return s } sum4(10, 10) func sumAll(number: Int...) -> Int { var sum = 0 for i in number { sum += i } return sum } sumAll(number: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // 튜플 let myInfo: [String: String] = ["이름": "공유", "이메일": "seungrry@daum.net", "핸드폰": "8940-4201"] func getName() -> String? { return myInfo["이름"] } func getEmail() -> String? { return myInfo["이메일"] } func getPhoneNumber() -> String? { return myInfo["핸드폰"] } getName() getEmail() getPhoneNumber() func getMyInfo() -> (String?, String?, String?, Int) { return (myInfo["이름"], myInfo["이메일"], myInfo["핸드폰"], myInfo.count) } let (myName, email, phone, infoCount) = getMyInfo() print("이름: \(myName), 이메일: \(email), 핸드폰: \(phone), 정보수: \(infoCount)")
'랭귀지 > SWIFT' 카테고리의 다른 글
[문법요약] Structure (0) | 2017.12.14 |
---|---|
[문법요약] 열거형(Enumeration) (0) | 2017.12.14 |
[문법요약] 배열, Set(집합), 딕셔너리(Dictionary) (0) | 2017.12.13 |
[문법요약] 조건 반복문 (0) | 2017.12.12 |
[문법요약] 변수 및 연산자 (0) | 2017.12.12 |
Comments