하핫 앙녕 상남자 Philip입니당 데헷 - mingu's
본문 바로가기

tuple decomposition // tuple decomposition = 튜플 분해 let anything = ("person", 400, "John", "mingu", 10.24) // use tuple decomposition let (type, age, who, genius, IQ) = anything // if use decomposition, no need to call it such as anything.type or anything.agesimply call it by their names. since we gave them names. example :print (type) ---------> "person"print (genius) ---------> "mingu" EASY
unnamed tuple, named tuple unnamed tuple let company = ["Aaron", "Bobbie", "Charlie", "Daemon"]company.0 --------> "Aaron"company.3 --------> "Daemon" named tuple let company = [manager: "Aaron", supervisor: "Bobbie", weirdo: "Charlie", useless: "Daemon"]company.manager --------> "Aaron"company.weirdo --------> "Charlie"
syntax optimization 스위프트 문법 최적화 closure 1. parameter 형식과 return 형을 생략한다2. parameter 이름을 생략하고 in 키워드도 지운 후 shorthand argument name으로 대체한다 ($0, $1, $2 ...)3. closure 에 포함된 코드가 단일 return문이라면 return 키워드를 생략한다 (implicit return)4. closure 가 마지막 parameter라면 trailing closure로 작성한다.5. argument label이 남아있다면 삭제한다6. 괄호 사이에 parameter 가 더이상 없다면 괄호도 없애버리자 // import Foundation let list = ["Apple", "Banana", "Cactus", "DeerMeat"] // where 파라미터로 인라인 클로..
while 반복문의 두가지 // while 반복문 var num = 100while num false로 판별됨num += 1}print(num) ------> 위 조건이 false이기 때문에 num += 1 코드가 실행되지 않음. 값은 100 // repeat while 반복문 var num = 100repeat {num += 1 -------> 일단 코드를 먼저 실행하기 때문에 100 + 1 이 됨}while num 101
for in loop의 다양한 활용 // 가장 기본적인 1부터 10까지의 합var sum = 0for counter in 1 ... 10 {sum += counter}print(sum) ------- 결과 = 55 // 짝수만 나열하기 for evenNumbers in stride(from: 2, to: 11, by: 2) {print(evenNumbers)} --------- 결과 = 2, 4, 6, 8, 10 // 구구단 만들어보기 for i in 2...9 { ----------2단부터 9단 까지for j in 1...9 { ----------i 를 곱하기 1부터 9까지print(\(i) X \(j) = \(i * j)}}이렇게 하면 2단부터 9단까지 싸그리 다 출력 오케이
카카오뱅크 저금통 잔고 확인하는 개꿀팁ㅋㅋ 안녕하십니까 오랜만에 인사드리는 실력파 상남자 Philip 입니다.. 저는 남자답게 외국에 거주하는 관계로 주거래 은행이 외국 은행이지만, 가끔 한국 은행에 거래할 일이(거의 없지만..) 있을 때는 신한은행 혹은 간편한 카카오뱅크를 이용합니다. 그러다가 최근에 우연히 카카오뱅크에서 저금통이라는게 신설되었다고 하여 가입했더니, 그 이후 매일 자정 1000원 미만의 동전 잔액들이 저금통으로 자동이체가 되어가고 있었습니다. 뭔가 신박하고, 나도모르게 조금씩이지만 저금을 하고 있는 느낌이 들더라구요? ㅋㅋ 근데 잔액은 확인을 못하고, 이모티콘으로 무슨 햄버거 같은거나 뜨고;; 그래서 여태껏 확인을 못하다가 제가 남자답게 알아내버리고 말았습니다 ㅋㅋㅋ 아래 사진을 확인하시죠 보시면 내 자산현황이 모조리 나오죠. ..
Type Alias Type alias = 일종의 별명을 만드는 것 let width: Double = 30.35let length: Double = 39.44 를 더 알아보기 쉽게 typealias square = Doublelet width: square = 30.35let length: square = 39.44 처럼 표현 가능.
Type safety 두 수의 데이터 타입이 같아야 연산을 실행할 수 있다 let a = 1.58let b = 100let result = a * b ------> 에러because a: Double, b: Int로 데이터타입이 다르기 때문 가능한 식let a = 1.58let b = 100let result = a * Double(b) print(result)------> Double 데이터타입으로 출력되기 때문에 값은 158.0print(Int(result)) -----> Int값으로 출력. 뒤에 소수점 없어짐 값 158 let result = Int(a * double(b)) -----> 값을 Int로 convertprint(result) ----> Int값 158