Posts

Optional Chaining

Apple says "Optional chaining is a process for querying and calling properties, methods, and subscripts on an optional that might currently be nil" . While processing if optional has value then the process will succeed otherwise the process will return nil . This querying, calling properties, methods and subscribe can be chained together and it failed gracefully if chain returns nil . An Alternative to Forced unwrapping: you will add question mark '?' after the optional value on which property you will wish to call properties, method, and subscripts if the optional is non- nil . Could an important interview question - The main difference between optional chaining and forced unwrapping is optional chaining fails gracefully whereas forced unwrapping will give runtime error when the optional value is nil . The result of optional chaining will return the same type value but that value will be wrapped with optional. So if Int is return t...

Implicitly Unwrapped Optional

As you have checked in the last article in which you have learned about the Optional, Optional value and Optional binding. Want to recall here you go -  Take a look! Sometimes you are sure when an optional has a value when it is set very first time. So it’s not necessary to check the if condition and unwrap the optional value for every time when you want to use that value. Because as you will be assuming that there is a value. So these kinds of optional defined as Implicitly unwrapped optional. So we use (!) to put in place of (?) right after the value which you want to make as optional. The primary use of implicitly unwrapped optional during the class initialization. As you might initial an optional value with some value or default value so.  Example: let optionalString: String ? = "optional" let forcedUnwrappedString: String = optionalString ! above line of code clearly, states we are storing the optional string in 'optionalString' and...

Swift Optional

Some people found it very confusing initially but when you will understand then it is simple. As we know optional tells itself about it. It's two cases. The first case when a value can be present for a type, then we need to unwrap if need to use it. Second case when a value can not be present for a type. We use '?' to mark a value as optional. class Student {     var name: String ? //  name becomes optional } When you declare the name string as optional by marking ' ? ' then it's valued automatically is set to nil.  NOTE: Swift 'nil' is not same as objective c 'nil'. In Objective-C, it is a pointer to an object which does not exist whereas in swift it's just an absence of a value for a type. let person = Student() print( person .name) When you access the name it will print a  nil . As there is no value assigned to name. Once we will provide a value to name, let say, "Swift". Then it looks like....

What's New in iOS 11.0

As Y'all know #WWDC17 already started. So here you can find new dishes !! in your dev plate. Few dishes like ARkit, Musickit and etc. You will loveit. I am just writing main points below for more details please check the release notes link in the bottom of the page. ********* General  ********* New - Support for binary (non-text) barcodes. Added API To: AV Foundation Core Image Sirikit  Support detection, decoding and creating barcodes with binary content Added  CIBarcodeDescriptor , a new barcode descriptor object to Core Image to provide interoperability with AV Foundation and the Vision APIs. ********* ********* New - MusicKit. ********* ********* MusicKit gives your app access to the full Apple Music catalog, and to the user’s library. MusicKit gives your app access to the full Apple Music catalog, and to the user’s library. Added and updated functionality in StoreKit for retrieving client tokens and storefront identifiers. Add...

Copy Vs Mutable Copy in iOS

It's found very confusing for most of the folks, who is not having much experience in Objective-C. Before starting I just to say: Just remember below lines- 1 - copy always creates an immutable copy means you can not modify the object. 2 - mutableCopy always creates a mutable copy  means you can modify the object Here onwards I try to explain copy and mutable copy with some examples: copy: NSArray *obj = [ NSArray arrayWithObjects : @"1" , @"2" , nil ]; NSArray *copyObj = [obj copy ]; NSArray *mutableObj = [obj mutableCopy ]; When you try to see the details of copyObj its clearly shows  __NSArrayI which tells that you can not modify this object Printing description of copyObjy: ( 1, 2 ) Same way  When you try to see the details of mutableObj its clearly shows  __NSArrayM which tells that you can modify this object Printing description of mutableObjy: ( 1, 2 ) As the copyObj is ass...

Functions in Swfit 3.0

As you have seen the previous post on Protocol , NSBlockOperation , Range Operators , Extension . Here you go with the new topic as Function in Swift 3.0.1 with Xcode 8.1. It will include detailed explanation about it. According to Apple’s  Swift Programming Language Book : Methods are functions that are associated with a particular type. Classes, structures, and enumerations can all define instance methods, which encapsulate specific tasks and functionality for working with an instance of a given type. Classes, structures, and enumerations can also define type methods, which are associated with the type itself. Type methods are similar to class methods in Objective-C. Functions A function contains some lines code which performs a specific task. You need to a name function, which explains what it does, call it whenever you need it. Defining and Calling Functions: Defining function -  func wishBday ( person : String ) -> String { let wishe...