Learn iOS development the Swift way: concise articles for fast learning!
-
Map in Swift
Hey Swift enthusiasts! Today, we’re diving deep into one of Swift’s most powerful higher-order functions: map. If you’ve ever wanted to transform elements in a collection without breaking a sweat, you’re in for a treat! What is Map? At its core, map is a method that transforms each element in…
-
Reduce in Swift
Greetings, Swift aficionados! Today, we’re diving into one of the most powerful yet often misunderstood higher-order functions: reduce. If you’ve ever needed to boil down a collection into a single value, reduce is about to become your new superpower. What is Reduce? The reduce method combines all items in a…
-
Filter in Swift
Hello, Swift developers! Today, we’re exploring another powerful higher-order function: filter. If you’ve ever needed to separate the wheat from the chaff in your collections, filter is about to become your new best friend. What is Filter? The filter method creates a new collection containing only the elements that satisfy…
-
CompactMap in Swift
Swift’s compactMap is a versatile and powerful method that combines mapping and filtering operations. It’s an essential tool for any Swift developer, allowing you to transform and clean up collections efficiently. In this post, we’ll explore compactMap through five practical examples, demonstrating its flexibility and utility in various scenarios. What…
-
Weak, Strong and Unowned in Swift
Weak and unowned keywords are used to define weak and unowned references to objects. A weak reference is a reference to an object that doesn’t prevent the object from being deallocated by the automatic reference counting (ARC) system. An unowned reference is a reference to an object that is assumed…
-
Separate UITableView/UICollectionView DataSource from a View Controller in Swift
View controllers can get really massive in some cases when you place the data source and delegate methods inside it when using a tableView or a collectionView. To overcome that you can separate them out. In this article we will take a look at how we can separate the data…
-
Fall Detection API in Swift for WatchOS
I was recently implementing the Fall Detection API in Swift/SwiftUI for watchOS, and I had a lot of trouble getting it working. The documentation was very sparse, and I ended up wasting a lot of hours trying to figure out how to use the API. I was finally able to get it working after…
-
The Observer Pattern in Swift
The Observer pattern is a design pattern that allows objects (observers) to register to receive notifications from another object (the subject). In Swift, the Observer pattern can be implemented using the ‘NotificationCenter‘ class and the ‘addObserver‘ method, like this: The SomeObserver class has a startObserving method that registers the handleNotification…
-
The Singleton Pattern in Swift
The Singleton pattern is a design pattern that ensures that only one instance of a class can be created, and provides a global point of access to that instance. In Swift, the Singleton pattern can be implemented using a static property and a private initializer, like this: In this example,…
-
Classes in Swift
A class is a data type that represents a reference type in Swift. Classes are similar to structs, but they are more powerful and flexible, and they are designed to be used as reference types rather than value types. To define a class in Swift, you use the class keyword…
-
Structs in Swift
A struct is a data type that represents a custom value type in Swift. Structs are similar to classes, but they are simpler and more lightweight, and they are designed to be value types rather than reference types. To define a struct in Swift, you use the struct keyword followed…
-
Closures in Swift
A closure is a block of code that you can use as a variable or pass to a function in Swift. Closures are similar to blocks in other programming languages, and they can be used for tasks such as defining a section of code to be executed at a later…
-
Arithmetic Operators in Swift
The arithmetic operators are used to perform basic mathematical operations on numbers in Swift. These operators include the following: Here are some examples of how you could use these operators in Swift: In this code, the a and b variables are declared and initialized with the values 5 and 2,…
-
Assignment Operator in Swift
The assignment operator (=) is used to assign a value to a variable in Swift. This is the most common and basic assignment operator in Swift. Here is an example of how you could use the assignment operator to assign a value to a variable: In this example, the score…
-
Type Annotations in Swift
Type annotations are used to specify the type of a value or variable in Swift. Type annotations are written immediately after the variable or value name, followed by a colon (:) and the name of the type. Type annotations are optional in Swift, but they can be useful for providing…