일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Firebase
- swift 5.9
- Combine
- arc
- ios
- SeSAC
- combinecocoa
- xcode
- RxSwift
- realm
- GCD
- observable
- KeyPath
- Firebase Analytics
- swift database
- 카카오뱅크 ios
- JSON
- uitableviewdiffabledatasource
- Tuist Swift
- swift db
- Subject
- ribs
- ios database
- 네트워크 통신
- SwiftUI
- Swift Tuist
- swift
- Subscribe
- swift 6
- Tuist
- Today
- Total
목록Swift 코딩테스트 준비 (9)
천원의 개발

프로그래머스 문제를 푸는 도중 진수를 변경하는 문제를 풀기 위해 공부하였다!! let a = String(15, radix: 2) // 2진수로 변경! print(a) // 1111 출력 let b = Int(a, radix: 2)! // 2진수를 다시 10진수로 변경! print(b) // 15 출력 https://developer.apple.com/documentation/swift/int/init(_:radix:)/
var dic = [5:0, 4:1, 3:2] print(dic.sorted()) // error 먼저 위처럼 dictionay에 sorted()함수를 사용하면 error가 난다! 그럼 어떻게 사용할까? var dic = [5:4, 4:1, 3:2] dic.sorted{$0.value < $1.value} // value 로 정렬 dic.sorted{$0.key < $1.key} // key로 정렬 dic.sorted{$0.value < $1.value}.map{$0.key} // 만약 value로 정렬후 key만 출력하고 싶으면 이런식으로
기존 for문은 break문을 통해 벗어날 수 있는데 중첩 for문은 어떤식으로 벗어날 수 있을까? outerLoop: for i in 1...10 { for j in 1...10 { let product = i * j print ("\(i) * \(j) is \(product)") //만약 product가 50이면 루프에서 빠져나온다. if product == 50 { print("구구단 그만!") break outerLoop } } } 위 처럼 outerLoop를 활용하면 된다.

import Foundation for i in stride(from: 5, to: 0, by: -1){ print(i) // 5 4 3 2 1 출력 }

소문자를 대문자로 변경! lowercased는 반대로 소문자를 대문자로 변경!