1.How can you write text case for completion handler The standard idiom is to use Xcode asynchronous testing APIs, mostly the XCTestExpectation class. Those are available since Xcode 6 so, if you are using a recent version, you should be covered ;)The general async test template is as follows: func testAsyncFunction() { let asyncDone = expectation(description: "Async function") ... someAsyncFunction(...) { ... asyncDone.fulfill() } wait(for: [asyncDone], timeout: 10) /* Test the results here */}This will block your test execution until the aforementioned function completes (or the specified timeout has elapsed). 2.why optional introduced in swift An Optional is a variable that can either have a value or be 'nil'.Compare this to your normal variable that must have a value and cannot be 'nil'.This has two benefits: It increases the readability and safety of your code since a conscious decision must be made as to whether a variable has a value. It increases the usefulness of the compiler since not only can it catch places where you might have forgotten a variable could be 'nil' (and force you to account for it), it can optimize the final machine code to take advantage of knowing a variable is guaranteed to have a value. 3.Difference between Class and structure Both class and structure can do: Define properties to store values Define methods to provide functionality Be extended Conform to protocols Define intialisers Define Subscripts to provide access to their variables Only class can do: Inheritance Type casting Define deinitialisers Allow reference counting for multiple references. 4.what is mean by app thinning in iOS App thinning is a concept for modern day interactive apps where there are a lot of resources. The App Store and OS install the app according to the device, with a minimal footprint. This helps in making the app which occupies less space, are easy to download and make use of all features. Faster downloads and minimum space occupancy gives a better app experience.There are three ways to implement App Thinning. Slicing Bitcode On-Demand Resources. 5.what is the use of completion handler in swift Whereas completion handler is a way (technique) for implementing callback functionality using blocks.A completion handler is nothing more than a simple block declaration passed as a parameter to a method that needs to make a callback at a later time. Note: completion handler should always be the last parameter in a method. A method can have as many arguments as you want, but always have the completion handler as the last argument in the parameters list. 6.Difference between escaping and non escaping closures 1. @nonescaping closures: When you are passing a closure as the function argument, the closure gets execute with the function body and returns the compiler back. As the execution ends, the passed closure goes out of scope and have no more existence in memory. Lifecycle of the @nonescaping closure: 1. Pass the closure as function argument, during the function call. 2. Do some additional work with function. 3. Function runs the closure. 4. Function returns the compiler back. 2. @escaping closures: When you are passing a closure as the function argument, the closure is being preserve to be execute later and function body gets executed, returns the compiler back. As the execution ends, the scope of the passed closure exist and have existence in memory, till the closure gets executed. There are several ways to escaping the closure: Storage: When you need to preserve the closure in storage that exist in the memory, past of the calling function get executed and return the compiler back. (Like waiting for the API response) Asynchronous Execution: When you are executing the closure asynchronously on despatch queue, the queue will hold the closure in memory for you, to be used in future. In this case you have no idea when the closure will get executed. When you will try to use the closure with these option the swift compiler will show the error. Lifecycle of the @escaping closure: 1. Pass the closure as function argument, during the function call. 2. Do some additional work in function. 3. Function execute the closure asynchronously or stored. 4. Function returns the compiler back. 7.How can you declare an optional method in a protocol swift. If you want to use optional methods, you must mark your protocol with @objc attribute:@objc protocol MyProtocol { @objc optional func OptionalFunction() } 8.What is mean by Optional Chaining In swift, optional chaining is the process in which we can query or call the methods, properties or subscripts of an optional that might be a nil. Generally, in swift optional chaining will return a values in two ways. If optional contains a value, then calling the property, method or subscript of an optional will return a value. In case if optional is a nil, then calling the property, method or subscription of an optional will return a nil. In swift, multiple queries can be chained together due to that if any link in the chain fails or return a nil value, the entire chain will fail and return a nilvalue.Swift Optional Chaining as an Alternative to Forced UnwrappingIn swift, if we want to work with the value which is inside an optional, we must unwrap it from the optional by placing an exclamation mark (!) after optional value same way we can add an optional chaining by placing a question mark (?) after the optional value on which we wish to call a property, method or a subscript if the optional is non-nil. The main difference is optional chaining will fail gracefully and return a nil when optional is nil but forced unwrapping will throw a runtime error in case if optional is nil. If we use optional chaining (?), we will get result values which is wrapped with keyword called Optional like Optional but if we use forced unwrapping (!), 9.Difference Between NSArray and Array in iOS Array is a struct, therefore it is a value type in Swift. NSArray is an immutable Objective C class, therefore it is a reference type in Swift and it is bridged to Array. NSMutableArray is the mutable subclass of NSArray.Example:var arr : NSMutableArray = ["Pencil", "Eraser", "Notebook"]var barr = ["Pencil", "Eraser", "Notebook"] func foo (var a : Array){ a[2] = "Pen"} func bar (a : NSMutableArray){ a[2] = "Pen"} foo(barr)bar(arr) println (arr)println (barr) Prints( Pencil, Eraser, Pen)[Pencil, Eraser, Notebook]Because foo changes the local value of a and bar changes the reference. It will also work if you do let arr instead of var as with other reference types. 10.Difference between Designated and convenience initializer in swift Standard init(Designated Initializer):Designated initializers are the primary initializers for a class. A designated initializer fully initializes all properties introduced by that class and calls an appropriate superclass initializer to continue the initialization process up the superclass chain.convenience init:Convenience initializers are secondary, supporting initializers for a class. You can define a convenience initializer to call a designated initializer from the same class as the convenience initializer with some of the designated initializer parameters set to default values. You can also define a convenience initializer to create an instance of that class for a specific use case or input value type. 11.What is the difference between Content hugging and content compression resistance priorities. Hugging => content does not want to grow Compression Resistance => content does not want to shrink and an example: Say you've got button like this: [ Button ] and you've pinned the edges to a larger superview with priority 500. Then, if Hugging priority > 500 it'll look like this: [Button] If Hugging priority < 500 it'll look like this: [Button] If superview now shrinks then, if the Compression Resistance priority > 500, it'll look like this [Button] Else if Compression Resistance priority < 500 ios training chennai Best iOS Training providing by GreensTechnology. Creating iOS apps using swift language. Greens providing 100% placement. Greens branches are : Adyar, Tambaram, OMR, Velachery, Annanagar. Greens Technologys providing best mobile app training with practical and theoretical sessions.