Posts

What is method chaining ?

In this article I will explain what is method chaining, where we can use and what are the advantages of using. Method chaining is a very less discussed and used  topic. Almofire iOS framework mostly uses the method chaining concept. The concept of method chaining is each method initialize some class properties or do something and returns self so that you can call another method on this.  Making functions chainable is quite easy and can allow us to write using an almost DSL-like syntax. Let’s consider the below method. func makeRequest(requestURL: String?, method: String?, parameters: [String: String ]?, completionHandler: @escaping ( [String:AnyObject] , bool) -> Void) In the above func if some parameter is not required we have to pass nil for that. Now Let’s consider the below APIRequest class. class APIRequest {     var url:URL?     var method = HTTPMethods.get     var params:[String:String]?     enum HTTPMethods: String { // http methods  

AutoFill OTP in iOS12 new feature (iOS12).

Image
So, finally Apple integrated autofill OTP in iOS 12…kudos to Apple. Because now a days many sites and apps required to confirm login with security code via text message.  Prior to iOS 12 it was little difficult for the user to enter the OTP as user had to toggle from OTP verification page to either messenger or Notification Centre. Then remember the entire OTP and type it back in the OTP verification page, which was really not a good user experience and consumes time. With iOS 12, you no longer have to jump from the verification page to Messages to retrieve your security code. Instead, iOS will present the security code as an auto-fill option. In iOS 12, when you receive an SMS message with an OTP or a verification code, the OS suggests the OTP in the keyboard’s quick type field . If your keyboard is present/on then at the top of the keyboard the OTP will display and just you have to press the OTP and it will fill in the textfield with the OTP automatically.. its so cool

Let’s understand what is optional in Swift and how to use !!

You use optionals in situations where a value may be absent. An optional represents two possibilities: Either there is a value, and you can unwrap the optional to access that value, or there isn’t a value at all. The example below shows how to declare optional variables.     1.    var optionalVariable1: String?     2.    var optionalVariable2: Int?     3.    func swapInt(int1: Int?, int2: Int?) // as a function argument     4.    func doSomething() -> String? // function return value as optional So basically you use optional when you think some variable’s value or function’s return value can be nil in some conditions. You can check the optional variable against nil before accessing, like below If optionalVariable1 != nil {      // your code } The example below uses the initializer to try to convert a String into an Int:     1.    let possibleNumber = "123"     2.    let convertedNumber = Int(possibleNumber)     3.    // convertedNumber is inferred to b