Posts

Showing posts from February, 2018

Multi threading? Concurrency? Asynchronous task? GCD (Grand Central Dispatch) ? in Swift Programming

Introduction of Grand Central Dispatch Grand central dispatch is the powerful api for multitasking with sync and async programming in iOS. Grand Central Dispatch (GCD) is a low-level API for managing concurrent operations. It will make your application smooth and more responsive. Also helps for improving application performance. Sometimes we are trying to perform multiple tasks at the same time that time most of the developer-facing application hang or freezing issue this is the common issue. That’s why we are using GCD to manage multiple tasks at the same time. DispatchQueue The DispatchQueue API like a company 🏢.. Who having staff units like junior level and senior level workers 👷🏼‍.  So now the company can take both heavy and light work with  there team. DispatchQueue.main.async {      // Perform your async code here } Concurrenct-  It’s starting multiple tasks at the same time but not guarantee for the finish at same time. Its can finish any order.

How to calculate height of a multiline String in Swift

Calculate Height of text to set dynamic height for complete Text import UIKit extension String { func heightWithConstrainedWidth ( width : CGFloat , font : UIFont ) -> CGFloat {        let constraintRect = CGSize ( width : width , height : . greatestFiniteMagnitude ) let boundingBox = self . boundingRect ( with : constraintRect , options : [ . usesLineFragmentOrigin , . usesFontLeading ] , attributes : [ NSFontAttributeName : font ] , context : nil )          return boundingBox . height      } } call this extension in your code CGFloat Text Height = (Text Label . text ?. heightWithConstrainedWidth (width: Text Label . frame . size . width , font: TextLabel . font ))!