Apart from other languages, when you write a class in Swift, It should have a initialiser.
To solve this we have to write init() function in that particular class. Just like below.

For example, look at the below class.
Here we have 5 variables.


The above error usually comes when you don’t initialize all variables in the class in init method.

Example

import Foundation

class SubCategory {
  
    var subCatId : String;
    var subCatName : String;
    var subCatImage : String;
    var catId : String
    var subCatActive : String
    
    init(SubCatId subCatId : String, SubCatName subCatName : String, SubCatImage subCatImage : String, SubCatActive subCatActive : String, CatId catId:String) {
        //  Initialize all member variables here...
        self.subCatId = subCatId;
        self.subCatName = subCatName
        self.subCatImage = subCatImage
        self.catId = catId;
        self.subCatActive = subCatActive;
    }
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.