문서에서 Int 의 Instance Method를 구경하던 도중 발견한 함수!
최근에 몫과 나머지를 사용한 문제를 종종 풀었는데 그때마다 직접 나누고 나머지를 따로 구했는데
한번에 구할 수 있는 함수를 알아두기 위해서 기록기록
func quotientAndRemainder(dividingBy rhs: Int) -> (quotient: Int, remainder: Int)
let x = 1_000_000
let (q, r) = x.quotientAndRemainder(dividingBy: 933)
// q == 1071
// r == 757
(몫, 나머지) 형태로 반환해준다.
x 선언할 때 _ 을 쓰는건 처음본다.. 신기하니 기억해두자
'iOS > STUDY' 카테고리의 다른 글
[iOS] Realm의 특징 (0) | 2022.03.22 |
---|---|
[cocoapods] M1 mac cocoapods 설치 오류 해결 (0) | 2022.03.16 |
[iOS] Diffable Data Source (CollectionView, TableView) (0) | 2022.03.10 |
[iOS] Identifiable 프로토콜 (0) | 2022.03.10 |
[iOS] extension + Generic where (0) | 2022.03.08 |