Swift

In this short tutorial, you will learn how to convert JSON string to a struct or a class in Swift. JSON String Let’s assume we have a web service endpoint which returns us a JSON string containing the following user details: {“firstName”:”Sergey”,”lastName”:”Kargopolov”,”email”:”[email protected]”,”userId”:”7fc0631b-7116-4d41-8d87-78f97b4dc543″} Swift Data Structure. Conforming to Codable or Encodable. We need to write Swift code…

Read More Convert JSON to Swift Class or Struct

This page contains different code snippets on how to work with Dictionary in Swift. Create Empty Dictionary // Create an empty dictionary let myDictionary = [String:String]() // Another way to create an empty dictionary let myDictionary2:[String:String] = [:] // Keys in dictionary can also be of type Int let myDictionary3 = [Int:String]()   Add Item…

Read More Working with Dictionary in Swift. Code Examples.

In this very short Swift tutorial, you will learn how to loop or iterate over a dictionary in Swift and print out key/value pairs. Loop Through Dictionary // Create a Dictionary with two elements var myDictionary = [“first_name”: “Sergey”, “last_name”: “Kargopolov”] // Loop through dictionary and print key/value pair for (key,value) in myDictionary { print(“\(key)…

Read More Loop Through Dictionary in Swift

In this Swift tutorial, you will learn how to use the flatMap function in Swift which will flatten an Array of Arrays into a single array of elements. Given Array of Arrays Let’s consider the following Array of Arrays. let numbers = [ [1,2,3,4], [5,6,7,8], [9,10,11,12]] The above array contains 3 arrays of integers. We can…

Read More How to Use flatMap in Swift. Code Examples.

In this short Swift tutorial, you will learn how to use one of the High Order Functions in Swift called map(_:) to apply a transformation to each element in an Array. Given an Array of Names Let’s consider an Array of String values: let names = [“sergey”, “michael”, “john”, “bill”, “tom”] All values in this Array…

Read More How to Use map(_:) in Swift. Code Examples.

To practice Swift programming and learn how to create and position UI elements programmatically in Swift you can use Xcode to create a new project or you can use Xcode Playgrounds. In this short tutorial you will learn how to use Xcode Playgrounds to run Swift code that creates a new UIView with a single…

Read More How to Use Xcode Playgrounds to Create UI in Swift

The below code example in Swift demonstrates how you can extend classes in Swift. Extending Class in Swift As an example, let’s learn how we can extend class Int.  Create a new Swift file in your current project and add there the following extension with a function that substructs a value. extension Int { func…

Read More Extending Classes in Swift. Class extension.

The below Swift code example demonstrates how to implement the Singleton Design Pattern in Swift. Singleton Design Pattern guarantees that only one Object of a class exists in the system even if a developer attempts to create multiple instances of it. Singleton Class example in Swift // Creating Singleton // Only one instance of this…

Read More Singleton Class in Swift. Code Example.

In Swift, a class or a struct can have multiple initializers which are used to create an instance of that particular type and set up its initial state. The code examples below show how to define a class with single or multiple initializers and how to create an instance of that class. Single Initializer class…

Read More Swift Class with Single and Multiple Initializers

Add Required Libraries to Xcode Project with Cocoapods pod ‘Firebase/Core’ pod ‘Firebase/Messaging’  Enable Push Notifications in Capabilities Tab Enable Background Modes in Capabilities Tab Note: Additionally to enabling the Background Modes, you also need to enable the Remote notifications mode by checking its checkbox as shown in the image below. AppDelegate.swift – Libraries to Import import…

The post Push Notifications with Firebase Cloud Messaging – Cheat Sheet appeared first on Swift Developer Blog.

Read More Push Notifications with Firebase Cloud Messaging – Cheat Sheet

Make your mobile app remotely configurable with Firebase Remote Config and you will be able to remotely enable or disable app UI elements, images, texts, labels and even change app behavior when needed. And all of it without a need to release a new version of the app to the app store and wait for…

The post Firebase Remote Config with Swift appeared first on Swift Developer Blog.

Read More Firebase Remote Config with Swift

hisI am becoming a big fun of Serverless architecture in the cloud and recently started reading a lot on how to build RESTful Web Services in the Cloud without starting your own server. Of course, I quickly came across Firebasebase Cloud Functions and I liked it a lot. Firebase Cloud Functions is one of those…

The post Firebase Cloud Functions with Swift appeared first on Swift Developer Blog.

Read More Firebase Cloud Functions with Swift

With this blog post, I would like to share with you how to send Silent Push Notification using CURL or Postman HTTP client via Firebase Cloud Messaging and how to receive silent push messages in your mobile app built with Swift. Silent push messages when received by your mobile app are not displayed to user…

The post Silent Remote Notifications with Swift and Firebase appeared first on Swift Developer Blog.

Read More Silent Remote Notifications with Swift and Firebase