Swift

Swift String Length (How to Count the Number of Characters)

To get the length of a string in Swift, call the String.count property. For example: Output: Replace ‘count’ with ‘length’ in Swift Swift developers decided to call the length of a string ‘count’. However, if you prefer ‘length’ over ‘count’ you can change it by writing an extension to the String class. Naively, you could […]

Swift String Length (How to Count the Number of Characters) Read More »

black marker on notebook

Swift Time Difference Between Date Objects in Seconds

To calculate the time difference between two Date objects in seconds in Swift, use the Date.timeIntervalSinceReferenceDate method. For example, let’s calculate how many seconds is between Christmas and New Year: Output: Date Difference Extension in Swift If you need to compute time differences between two dates more often in your project, feel free to write

Swift Time Difference Between Date Objects in Seconds Read More »