Search Your Question

Showing posts with label Futurism Technologies. Show all posts
Showing posts with label Futurism Technologies. Show all posts

Difference between type method and Instance method?

Type Method: We can call the method using Struct, Class, or Enum name. The method can be static or Class for making such methods. Static method can not be override but class method can be override.

Instance Method: We can call normal method using making instance of strcut or class. This methods are called instance method.

Difference between Swift and Objective C

 


 SWIFT  

 OBJECTIVE C


Swift is a general-purpose, high-level programming language that is highly concerned about safety, and performance.

Objective C is a general-purpose language that is considered a superset of C language it was designed with the aim of providing object-oriented capabilities.


It was developed by Chris Lattner with eventual collaboration with other programmers at Apple.

It was developed by Brad Cox and Tom Love at their company Stepstone.


It was influenced by Objective C, Rust, Ruby, and Python.

It was influenced by C and Smalltalk.


Swift first appeared on the year 2014.

Objective C first appeared on the year 1984.


Swift is a static type.

Objective C is dynamic type.


Swift is apache licensed open-source project.

Objective C is licensed under General Public License.


It only has classes.

It has both Structs and classes.


It was designed for building apps for iOS, Mac, Apple TV, and Apple Watch.

Objective C was designed to be Smalltalk messaging features.


Swift polymorphism does not exist directly.

Polymorphism in Objective C exists directly in compile time.


It uses true and false values.

It uses YES and NO values and also BOOl.


Swift has multiple types of templates than Objective C.

Objective C lacks templates than Swift.

What is remote config in firebase

Change the behavior and appearance of your app without publishing an app update, at no cost, for unlimited daily active users.

Firebase Remote Config is a cloud service that lets you change the behavior and appearance of your app without requiring users to download an app update. When using Remote Config, you create in-app default values that control the behavior and appearance of your app. Then, you can later use the Firebase console or the Remote Config backend APIs to override in-app default values for all app users or for segments of your user base. Your app controls when updates are applied, and it can frequently check for updates and apply them with a negligible impact on performance.

What is mutating in swift?

Ans :

If you have ever tried using the mutating keyword in your class methods in Swift, the compiler will definitely yell at you because you are doing something wrong.
In swift, classes are reference type whereas structures and enumerations are value typesThe properties of value types cannot be modified within its instance methods by default. In order to modify the properties of a value type, you have to use the mutating keyword in the instance method. With this keyword, your method can then have the ability to mutate the values of the properties and write it back to the original structure when the method implementation ends.
Below is a simple implementation of Stack in Swift that illustrates the use of mutating functions.

struct Stack {
     var items = [Int]() // Empty items array
    
    mutating func push(_ item: Int) {
        items.append(item)
    }
    
    mutating func pop() -> Int? {
        if !items.isEmpty {
           return items.removeLast()
        }
        return nil
    }
}

var stack = Stack()
stack.push(4)
stack.push(78)
stack.items // [4, 78]
stack.pop()

stack.items // [4]

You can change the value of items by creating an instance of Stack. But without mutating keyword function can not change property.

Classes are reference type whereas Structures and Enumerations are of a value type in swift. What does that mean is that a class object shares a single instance of the object and passes the same reference if passed to any function or new object whereas the value type is the one which creates a copy of it and passes only the value.
If we try to change any variable inside a class it’s straightforward.

Explain defer keyword or defer statement in Swift

Ans : Defer block is executed just before return statement or exit of block. Let's have a look to following chunk of code for better understanding

      func defer()  { 
          print("Start") 
          var value: String? 
         defer { 
              if let v = value { 
                   print("Ending execution of \(v)")
              } 
        } 
      value = "defer function" 
      print("End") 
   }

So printing sequence is like following :

Start
End
Ending execution of defer function

So in short defer block will be called lastly in the current block. It will be executed in any case like before return, before the break, before throw exception. Yes, if exception comes, then also defer block will be called before program crash or going to exception.

If there is multiple defer block in same method, Then defer block will execute from down to up side.