Suleman Ali’s Post

View profile for Suleman Ali, graphic

Senior iOS Developer | Crafting High-Performance Mobile Solutions | Expertise in Swift, Objective-C, and Cutting-Edge App Development

Mastering Grand Central Dispatch (GCD) and Operations in iOS Swift 103 Advanced GCD Features Dispatch Groups: Manage a group of tasks and get notified when they all complete. ``` let group = DispatchGroup() let queue = DispatchQueue.global() group.enter() queue.async { fetchData() group.leave() } group.enter() queue.async { print("Another task running...") sleep(1) print("Another task done!") group.leave() } group.notify(queue: DispatchQueue.main) { print("All tasks are completed.") } ``` Dispatch Semaphores: Control access to a resource with a limited number of threads. ``` let semaphore = DispatchSemaphore(value: 1) DispatchQueue.global().async { semaphore.wait() print("Accessing shared resource...") sleep(2) // Simulate work print("Done with shared resource.") semaphore.signal() } ``` #iOSDevelopment #Swift #GCD #Operations #Concurrency #MobileDevelopment #iOS #SwiftUI #CleanCode #CodeQuality #AppPerformance #MobileApps #TechTips #Programming #Developer #SwiftProgramming #Xcode

To view or add a comment, sign in

Explore topics