Category: Develop

  • Closures, Extensions and Generics in Swift

    Closures Closures are self contained lines of code that can be passed around the application and similar to blocks in Objective-C. A typical closure syntax in Swift looks as shown below Closure Syntax { (parameters) -> return type in statements } Example closure in Swift var greetings = { (name:String, message:String) -> (String) in message…

  • 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…

  • Assertions supported in XCTest

    Here you can find the list of Assertions supported by XCTest and it is essential to know all these assertion if you are practicing Test Driven Development in IOS. You can get this list from XCTestAssertions.h XCTFail(<#format…#>) – This unconditionally fails the test. XCTAssertNil(<#a1#>, <#format…#>) – Failure message when object is not nil. XCTAssertNotNil(<#a1#>, <#format…#>)…

  • Tuples, Enums and Protocols in Swift

    Tuples in Swift allows user to assign group of values to a variable, constant and even return parameter of a function. In the below example, a employee constant is assigned Int and String values. And to access these parameters, we need to use .0 and .1 [code language=”swift”]let employee = (103, “Deepak”) employee.0 employee.1[/code] Now…

  • How to display line numbers in Xcode

    Listed below are the steps to display line number in Xcode editor window. This is quite useful when you are working in a ground and want to communicate the line number of statement to other members. Click Xcode menu option and select Preferences from the menu list In the Preferences window, click Text Editing tab.…

  • How to record and play sound in Swift

    In this tutorial, we are going to see the required steps to record and play sound in Swift Programming language using AVAudioRecorder and AVAudioPlayer Download source code from github (SoundController.swift) User Interface The user interface for this demo is simple with two buttons, one for recording and another for playing sound. Create corresponding IBAction and…

  • UITextFieldDelegate in Swift

    This is a beginners tutorial on UITextFieldDelegate in Swift. We are going to see how to use UITextFieldDelegate by writing a Simple Interest Calculator. Download the source code from here This calculator uses UILabels and TextFields for displaying and accepting amount and interest. We are going to use the UITextFieldDelegate method to navigate from “Principal…