Skip to content

Random unification in Swift 4.2

In the beginning of this year I blogged about how to generate random float and integers. Meanwhile, SE-0202 “Random Unification” got implemented in Swift 4.2 making my additions unnecessary. Let’s take a look how to use new API for getting random numbers. Random integers, floats and booleans In my own implementation I was extending range with a function named random(). Swift 4.2 took different path. Instead, it adds functions like static func random(in range: Range, using generator: inout T) -> UInt64 where T : RandomNumberGenerator to FixedWidthInteger, BinaryFloatingPoint and Bool.… Read more Random unification in Swift 4.2

Taking photos on iOS

This time we will take a look on how to take photos and browse them on iOS. Using UIImagePickerController Creating user interface for taking photos consists of presenting an instance of UIImagePickerController. Controller needs a delegate and source type what defines if we are going to take a photo or pick a photo from the library. But even before creating the controller it is required to call isSourceTypeAvailable(_:) class method and verifying if the source type is available. For example, it returns false if picker’s sourceType is set to UIImagePickerController.SourceType.photoLibrary… Read more Taking photos on iOS

Singly linked list with generics in Swift

In this post we will go over basic usage of generics in Swift by building a simple singly linked list. Introduction to generics Generic code is code where the functionality is described without using specific types. Meaning, the code can use any types what match with constraints (if there are any). It’s best to take a look on an example. See how separate functions can be replaced with a single implementation. Generic implementation defines a placeholder for a type (in angle brackets), in those examples T was used (can be… Read more Singly linked list with generics in Swift