본문 바로가기

4

[Swift & iOS] Swift에서 'stride' 함수 사용하기 Swift에서는 일정한 간격으로 반복되는 값을 생성하기 위해 stride 함수를 사용할 수 있습니다. 이 함수는 숫자의 시퀀스를 생성하는 데 유용하며, 두 가지 버전이 있습니다1. stride(from:to:by:) 2. stride(from:through:by:) 1. stride(from:to:by:)시작 값에서 종료 값을 포함하지 않는 시퀀스를 생성합니다stride(from: start, to: end, by: step) start: 시작 값end: 종료 값 (포함되지 않음)step: 증가 값예시let sequence = stride(from: 0, to: 10, by: 2) for value in sequence { debugPrint(value) } 출력결과02468 2. stride(from.. 2024. 7. 22.
[Swift& iOS] View reload 관련 에러 RxSwift로 CollectionView를 reloadData() 할 때 아래와 같은 에러가 발생하였습니다. Maybe delegate was already set in xib or storyboard and now it's being overwritten in code. 에러 내용은 간단합니다. 이미 delegate나 설정 되어있다는것입니다. 저 같은 경우 이미 Observable bind를 통해 CollectionView를 생성하였고 func fetchData() { output.showGearDetail .do{ self.gearDetail = $0 } .map{ $0.images } .do{ self.pageControl.numberOfPages = $0.count self.pageControl.. 2022. 2. 8.
[Swift & iOS] Unicode 코드 변환 관련 파이썬에서는 간단하게 ord 내장함수를 사용 하여 문자를 유니코드로 변환을 해줍니다 Swift 에서는 어떻게 하는지 알아보겠습니다 Unicode to Int let str: String = "a" let number: Int = Int(UnicodeScalar(str)!.value) or let number: Int = Int(UnicodeScalar("a").value) print(number) // 97 (Uint32) UnicodeScalar 함수에 변환 하고 싶은 문자를 넣으면 UInt32 타입의 값의 아스키코드를 얻을 수 있습니다 Int to Unicode let unicode: String = String(UnicodeScalar(97)!) print(unicode) // "a" 1번 방법과는.. 2021. 11. 19.
[Swift & iOS] TabBarController에 연결 된 ViewController 접근 하기 TabBarController를 생성 하게 되면 기본 2개의 ViewController이 같이 생성 된다. 물론 ViewController을 더 생성하거나 삭제하는 것이 가능 하다. 그럼 TabBarController에서 연결 된 ViewController에 접근 하려면 어떻게 해야 할까 . 먼저 UITabBarController을 상속한 Class를 생성 후 viewControllers 프로퍼티를 보면 TabBarController에 연결 된 ViewController을 볼 수 있다. print 결과 연결 된 viewController들을 볼 수 있다. 당연히 custom class에 class가 지정 되어 있어야 한다. prepare 함수 사용 하여 값을 넘길 때 위에 선언 한 MainTabBarCo.. 2021. 8. 7.