Skip to main content

Posts

What is the difference between class and structure in Swift?

  The Main difference in Class and Structure            Classes are reference types.  Structures are value types. Classes have an inheritance that allows one class to inherit the characteristics of another. Structures do not support inheritance. Class ( R eference Types  ) Reference Type When you copy a reference type, each instance shares the data. The reference itself is copied, but not the data it references. When you change one, the other changes too. Inheritance Classes have an inheritance that allows one class to inherit the characteristics of another. Initializer We have to define the initializer manually. Storage Class instances are stored on the heap. Thread Safe Classes are not fully thread − safe. Example :   class EmployeeList { var name: String var age: Int init(name: String, age: Int) { self.name = name self.grade = grade } } let emp1 = EmployeeList(name: "Dixit Akabari", age: 27) let emp2 = emp1 emp2.name = "M

Cannot assign to property 'self' is immutable.

struct   is a   value type . For value types, only methods explicitly marked as mutating can   modify   the properties of self, so this is not possible within a   computed   property. Structs are value types which means they are copied when they are passed around.So if you change a copy you are changing only that copy, not the original and not any other copies which might be around.If your struct is immutable then all automatic copies resulting from being passed by value will be the same.If you want to change it you have to consciously do it by creating a new instance of the struct with the modified data. (not a copy) If you change  struct  to be a  class  then your code compiles without problems.

Record UIView In iOS Swift (XCode)

This blog used for helping to Record a UIView.                     It records animations and actions as they happen by taking screen shots of a UIView in a series and then creating a video and saving it to your app’s document folder.  Create  Recorder.swift  File .      This file take screenshot of UIView in a series and save that images in document directory.   import UIKit @objc public class Recorder : NSObject {          var displayLink : CADisplayLink ?     var outputPath : NSString ?     var referenceDate : NSDate ?     var imageCounter = 0          public var view : UIView ?     public var name = "image"     public var outputJPG = false          var imagesArray = [ URL ]()          public func start () {                  if ( view == nil ) {             NSException (name: NSExceptionName (rawValue: "No view set" ), reason: "You must set a view before calling start." , userInfo: nil ). raise ()         }         else {