swift Basics - siddhpatil6/iosInterviewQuestions GitHub Wiki

How to Concatinate String

let a = "Hello"
let b = "World"

let first = a + ", " + b
let second = "\(a), \(b)"

Why to use extensions and how to use it?

Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for which you do not have access to the original source code (known as retroactive modeling). Extensions are similar to categories in Objective-C. (Unlike Objective-C categories, Swift extensions do not have names.)

Extensions in Swift can:

  • Add computed instance properties and computed type properties

  • Define instance methods and type methods

  • Provide new initializers

  • Define subscripts

  • Define and use new nested types

  • Make an existing type conform to a protocol

In Swift, you can even extend a protocol to provide implementations of its requirements or add additional functionality that conforming types can take advantage of. For more details, see Protocol Extensions.

In Project, we use it to add more feature to color by giving alpha UIColor+FlatColor custom notification

How to call Next ViewController on Condition in StoryBoard

This helps to call next view controller

self.performSegue(withIdentifier: "registerflow", sender: nil)
  • Here we mention condition for segue which data to pass on which controller public override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier=="registerflow" { let destination=segue.destination as! RegisterScreenVC } else if segue.identifier=="UserLogin" { let destinaion = segue.destination as! UserLoginVC

      }
    

    }