Tag: Swift
Class and Struct in Swift
Download the playground file from github (Classes and Struct) Class A class is a blue print for a real-word entity such Player, Person etc. and it is used for creating objects. Class can have properties to store values and methods to add behaviour. Let us see this with an example class called Rectangle which has…
Optional binding and Optional Chaining
Swift has a feature that lets users to assign optional value to a variable or a constant. Optional variable or constant can contain a value or a nil value. Let us take the following example which tries to find a given string in a array of string. Optional Binding var fruits = [“Apple”,”Orange”,”Grape”,”Mango”] let searchIndex…
Clear CocoaPods cache, re-download and reinstall all pods
Here is the code snippet to clear CocoaPods cache then re-download and reinstall all pods. rm -rf “${HOME}/Library/Caches/CocoaPods“ rm -rf “`pwd`/Pods/“ pod update Source
PDFKit – View, Annotate PDF file in Swift
In this demo, we will be using PDFKit to View and Annotate PDF file. Let us start by selecting a Single View App template and name the project as PDFDemo. For this demo, we will be using a PDF file “TheWakingLights.pdf” and this can downloaded from the github project folder. Now drag and drop this…
CoreData tutorial in Swift 5 using NSFetchedResultsController
Let us see an example TaskManager app using CoreData written in Swift Programming language. This app provides the following functionality Allow users to enter new task Update existing task delete task You can download source code for this project from Github. If you are familiar with user interface then move on to the Core Data…
Get your current address in Swift (Swift 5)
In this Swift tutorial, we will see the steps required for using CoreLocation framework and retrieve the latitude and longitude of the location. Then use the CLGeocoder to reverse geocode the latitude and longitude details. This is a very basic tutorial that retrieves the location details on tap of a button and displays the information…
Swift – WebView demo
Updated for Swift 5In this short tutorial, we will see an example in Swift programming language using UIWebView. The WebView will load a webpage and provide option to refresh, stop, go back and go forward. This tutorial should give a brief overview on how to declare IBAction, IBOutlets and use Objective-C classes (NSURL and NSURLRequest)…
How to programmatically add AutoLayout constraints?
AutoLayout solves the mystery when designing app for more than one screen size and for both Portrait and Landscape orientation. This is done by adding constraints to the views using various Auto Layout options available as part of Interface Builder. As an iOS developer, you can also add these constraints programmatically using NSLayoutConstraints or Visual…