본문 바로가기

ios29

Understanding Swift Performance https://developer.apple.com/videos/play/wwdc2016/416/ Dimensions of Performance 그래프가 왼쪽에 있을 수록 성능이 좋다! Allocation Stack 스택 포인터를 이용하여 빠르게 allocate/deallocate 가능 Heap Advanced data structure 동적 lifetime으로 메모리 할당 가능 (스택을 불가능) 할당을 위해 메모리에서 사용하고 있지 않은 블록을 찾는 과정 필요 deallocate를 위해 메모리의 적절한 위치에 블록을 reinsert 해야함 Thread Safety를 위한 오버헤드 발생 여러 스레드가 동시에 힙에 접근 할 수 있다. 따라서, lock 또는 다른 동기화 메커니즘을 통해 무결성을 보호해야 한다.. 2023. 3. 13.
Combine 중복 바인딩 문제 (tableViewCell) 관련 PRhttps://github.com/sopt-makers/SOPT-iOS/pull/66문제 상황위와 같은 뷰에서 각 cell의 체크 박스(버튼)의 토글 이벤트를 combine으로 활용하여 VC와 바인딩하려고 한다.이 때,위처럼, 버튼 클릭을 해도 토글이 되지 않고 다시 원상태로 돌아오는, 정확히 말하면 두번 토글되어 본래 상태로 돌아오는 문제가 발생했다.VC에서 cell의 publisher를 구독하여 print 해보면 클릭하면 이벤트가 연속해서 2번 발생하는 상황이었다. 코드VCpublic func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { guard.. 2023. 2. 15.
CollectionView MultipleSelection 영상처럼 cell을 여러개 선택할 수 있도록 구현하고 우측 상단에 선택된 총 cell의 개수를 UI로 보여주기를 원한다. 시도 방법 func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { guard let cell = collectionView.cellForItem(at: indexPath) as? ImageListCollectionViewCell else { return false } print(cell.isSelected) if cell.isSelected { self.total -= 1 } else { self.total += 1 } return true } sho.. 2023. 2. 15.
Explore structured concurrency in Swift 프로그래밍 언어의 초기에는 instructions의 순서대로 작성되어 가독성이 좋지 않았다. 하지만 오늘날의 언어는 structured programming을 통해 control-flow가 통일성(uniform)을 가지게 되어 가독성이 좋아졌다. (if - then 구문) Swift는 Static Scope를 사용한다. Concurrency에서의 Structured Programming 썸네일 이미지를 가져오는 전통적인 방식의 비동기 처리 코드 (escaping closure 사용) func fetchThumbnails( for ids: [String], completion handler: @escaping ([String: UIImage]?, Error?) -> Void ) { guard let id .. 2023. 2. 11.
Meet AsyncSequence https://developer.apple.com/videos/play/wwdc2021/10058/ AsyncSequence 예시 코드 @main struct QuakesTool { static func main() async throws { let endpointURL = URL(string: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv")! // skip the header line and iterate each one // to extract the magnitude, time, latitude and longitude for try await event in endpointURL.lines.dropFirst() .. 2023. 2. 11.
Use async/await with URLSession https://developer.apple.com/videos/play/wwdc2021/10095/ 서버 통신을 통해 사진을 불러오는 기능을 async/await 와 URLSession을 사용해 구현해보자! 기존의 방식 (completion Handler) 문제점 스레드 문제가 발생 할 수 있다. (Data Race) 위의 코드에서 총 3번의 completionHandler를 호출부에서 오직 한 곳만 main queue에 dispatch 되고 있다. → 버그 발생 가능 에러 처리 또한 제대로 되어 있지 않다. Fetch Photo with async/await func fetchPhoto(url: URL) async throws -> UIImage { let (data, response) = try aw.. 2023. 2. 11.