KB Tag: SwiftProgramming

  • How to exhibit UIPickerView in UIAlertController

    When you desire to describes the picker view in UIAlertController in the center of the screen or you need to show bottom action sheet. It will explain better view in iOS to implement picker view in UIAlertController rather than creating in UIView it also saves your many code to write and complexity too. An example okay…

  • How to check internet availability using swift

    Internet Availability For every application, it is mandatory to ensure internet connection is available or not. So you can confirm the internet availability by using SCNetworkReachabilityAPI of  SystemConfiguration Framework which is by default offered in iOS, You do not have to utilize any third party library for that. Follow these steps to ensure internet availability:- build a new…

  • Dictionaries in Swift

    You may know that in Swift arrays to read out a value, you can call it’s index value similar to: var someArray = [“Farhan”, “Syed”, “March”, “19”, “1996”] someArray[0] Instead of remembering the index value that is assigned to each value we can re-write this with a dictionary. By dictionaries, instead of arbitrary numbers you have read…

  • Conditional Statements in Swift

    When you desire your code to perform only if a certain condition is true then you can use an if statement. You can execute a if like so: var brand = “Apple” if brand == “Apple” { print(“Brand is Apple”) } An  if statement is begin with if followed by the condition then a block, open and close braces. Let’s include a else after the if:…

  • How to create funtion in Swift

    In this blog, I’ll explain you how to create simple functions in Swift along with a little more complex functions that take parameters and can return a value. An easy method to obtain some practice would be to open and follow beside. Let’s begin with a simple function: func someFunctionName () { print(“Hello World!”) }…

  • How to fetch JSON using NSURLSession

    In this tutorial I will discuss about iOS application that fetches some JSON from a web API While building this application we will be following: Functions Arrays Dictionaries NSURLSession Open Xcode Let’s open Xcode and build a single view application. Go to ViewController.swift. Your default ViewController.swift should appear like this: import UIKit class ViewController: UIViewController { override func viewDidLoad()…

  • How to use Generics in iOS swift

    Generics are an interesting concept, and they permit you to reuse your code for several types. Let’s stare at an example: func swapInts(_ a: inout Int, _ b: inout Int) {     let temporaryB = b     b = a     a = temporaryB } swapInts function obtains 2 Ints and swaps them. Here is a sample usage:…

  • Closures and Higher Order Functions(Map, filter,forEach,reduce,Flatmap)

    Closures and Higher Order Functions One of major key features in Swift is the closure. In Objective C, closures are known as blocks. The perception is similar, but they’re much more influential in Swift. Simply set, a closure is a function without a name. Swift closures are first class types, meaning that they can be allocate to…

  • Size classes in Xcode 8

    Auto layout is vast for making adjustments to a layout based on constraints, but sometimes a layout requires more important adjustments based on the device type, screen size or orientation. Probably you may need: A large font size in the big iPad Pro screen than on the small iPhone SE A sight to be laid…

  • Advanced Autolayout with xcode 9

    Auto layout is a constraint based layout system; it permits developers to create a responsive and adaptive User Interface. Generally developers find it difficult to study and avoid using it. While developing an app today you won’t be able to manage to keep going without it. Now we are going to start with the basic…