Search Your Question

Showing posts with label Thyrocare. Show all posts
Showing posts with label Thyrocare. Show all posts

What is category?

Ans : It is used to extend the functionality of the class. Implementation of category is in different file with name like classname + categoryname.h and .m file.

Read : Differnce between Category and Extension


Difference between Static Constructor and Private Constructor

Ans : I have asked this question for C# language.

Private Constructor :  It is used to prevent class to be instantiated and to be inherited. Class can have multiple private constructor and can be called by any other constructor.

Static Constructor :   It is used to initialise static members of a class. We can't say when it is called and It is called by CLR and not called by manually. It is called just before first instance of class is created. Class can have a only one static constructor. This constructor is called only once in lifetime of application.

What is size class? Explain with Example.

Ans : 
Size Classes are groups of screen sizes that are applied to the width and height of the device screen. The two Size Classes that exist currently are Compact and Regular.

The Compact Size Class refers to a constrained space. It is denoted in Xcode as wC (Compact width) and hC (Compact height).

The Regular Size Class refers to a non-constrained space. It is denoted in Xcode as wR (Regular width) and hR (Regular height).

iPhone : Most iPhone devices will use the Compact width (wC) size class in each orientation with some exceptions.
The iPhones 6/7 Plus can inherit the Regular width (wR) size class resulting in the ability to use functionality normally reserved for the iPad, such as the split-view pane. Split-VIew pane is speciall made for iPad.

iPad : All iPad devices use the Regular width (wR) size class regardless of landscape or portrait orientation. In both horizontal and vertical landscape, the iPad will use a split-view pane to take advantage of the available screen space because it falls within this unconstrained size class.

Controlling the UI with Size Classes

In most cases, specifying the width class is sufficient when laying out your app; however, you can use the height class to customize your app as well. For example, if you use a split-view pane in an iPad app, users will see the same pane on iPhone Plus in landscape orientation because they both inherit the Regular width (wR) size class.

If that is not your intention, you can exclude a split-view pane from appearing on the 7 Plus by specifying both the width and height Size Classes. This works because the height of an iPhone Plus in landscape orientation is compact (hC) while all iPad devices have a regular height (hR).

You can also use Size Classes to target specific UI elements like font colors, font sizes, drop shadows, view colors and more to adapt to users’ device screen. These variations give you added control as to how your UI can adapt to different devices and orientations that your user may be using.




What is extension and How to use it?

Ans :
Swift Extension :

Add a new swift file with File > New > File... > iOS > Source > Swift File, but you can call them what you want.
The general naming convention is to call it TypeName+NewFunctionality.swift

Make extension of Double

Double+Conversions.swift

import Swift // or Foundation

extension Double {

    func celToFahren() -> Double {
        return self * 9 / 5 + 32
    }

    func fahrenToCel() -> Double {
        return (self - 32) * 5 / 9
    }
}

How to make extension:

let boilingPointCel = 100.0
let boilingPointFaren = boilingPointCel.celToFahren()
print(boilingPointFaren) // 212.0

Make extension of UIColor

UIColor+CustomColor.swift

import UIKit

extension UIColor {

    class var customGreen: UIColor {
        let darkGreen = 0x008110
        return UIColor.rgb(fromHex: darkGreen)
    }

    class func rgb(fromHex: Int) -> UIColor {

        let red =   CGFloat((fromHex & 0xFF0000) >> 16) / 0xFF
        let green = CGFloat((fromHex & 0x00FF00) >> 8) / 0xFF
        let blue =  CGFloat(fromHex & 0x0000FF) / 0xFF
        let alpha = CGFloat(1.0)

        return UIColor(red: red, green: green, blue: blue, alpha: alpha)
    }

}
See here also.

Using extension :

view.backgroundColor = UIColor.customGreen

Summary : Once you define an extension it can be used anywhere in your app just like the built in class functions. In Objective-C extensions are known as categories.

Objective C Extension : 

In objective c, when you want to make behavior of some property private you use class extension.
-> it comes with .m file only.
-> mainly for properties.
The implementation of the extension must be in the main @implementation block of the file.
Extension can only be added to the classes whose source code is available because compiler compile the source code and extension at same time.