Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Must call a designated initializer of the superclass 'Navigator'" error has occurred. #378

Closed
nashirox opened this issue Jan 28, 2016 · 4 comments

Comments

@nashirox
Copy link

I'm using ObjectMapper with Realm with these version.

  • ObjectMapper 1.1.1
  • Realm 0.97.0
  • Swift 2.1.1
  • Xcode 7.2

But when added new class with Realm + ObjectMapper, an error has occured.
below line is error message.

Must call a designated initializer of the superclass 'Navigator'

and thisi is new class i added.

import RealmSwift
import ObjectMapper

class Navigator: Object, Mappable {

    dynamic var id : Int              = 0
    dynamic var name : String         = ""
    dynamic var imageURL : String     = ""
    dynamic var coverImageURL : String = ""
    dynamic var totalPlayCount : Int  = 0
    dynamic var totalFavCount : Int   = 0
    dynamic var createdAt : NSDate    = NSDate()
    dynamic var updatedAt : NSDate    = NSDate()

    var guides : [Guide] {        
        return linkingObjects(Guide.self, forProperty: "navigator")
    }

    override class func primaryKey() -> String {
        return "id"
    }

    override static func indexedProperties() -> [String] {
        return ["name", "imageURL", "totalPlayCount", "totalFavCount"]
    }

    // Mark: - ObjectMapper

    required convenience init?(_ map: Map) {
        self.init()
    }

    func mapping(map: Map) {
        id             <- map["id"]
        name           <- map["name"]
        imageURL       <- map["avatar_url"]
        coverImageURL  <- map["cover_url"]
        totalPlayCount <- map["listen_count"]
        totalFavCount  <- map["favorite_count"]
        createdAt      <- (map["created_at"], ISO8601DateTransform())
        updatedAt      <- (map["updated_at"], ISO8601DateTransform())
    }
}

this class works correctly.

import RealmSwift
import ObjectMapper

class Guide: Object, Mappable {

    dynamic var id : Int                = 0
    dynamic var title : String          = ""
    dynamic var spotName : String       = ""
    dynamic var placeId : String        = ""
    dynamic var explanation : String    = ""
    dynamic var category : String       = ""
    dynamic var totalPlayCount : Int    = 0
    dynamic var totalFavCount : Int     = 0
    dynamic var latitude : Double       = 0.0
    dynamic var longitude : Double      = 0.0
    dynamic var createdAt : NSDate      = NSDate()
    dynamic var updatedAt : NSDate      = NSDate()

    dynamic var navigator: Navigator?
    var relatedGuides = List<Guide>()

    override class func primaryKey() -> String {
        return "id"
    }

    // インデックス設定
    override static func indexedProperties() -> [String] {
        return ["name", "category", "firstImageUrl", "totalPlayCount"]
    }

    //  override static func ignoredProperties() -> [String] {
    //    return []
    //  }

    // Mark: - ObjectMapper

    required convenience init?(_ map: Map) {
        self.init()
    }

    func mapping(map: Map) {
        id             <- map["id"]
        title          <- map["name"]
        spotName       <- map["spot.name"]
        explanation    <- map["description"]
        category       <- map["category.name"]
        totalPlayCount <- map["listen_count"]
        totalFavCount  <- map["favorite_count"]
        latitude       <- map["geometry.latitude"]
        longitude      <- map["geometry.longitude"]
        createdAt      <- (map["created_at"], ISO8601DateTransform())
        updatedAt      <- (map["updated_at"], ISO8601DateTransform())
    }
}

so i'm confused what to do next.
someone please give me advices.

@tristanhimmelman
Copy link
Owner

Hi there, I just tested this code and I am not getting any errors. Are you still having this problem?

@Andr3y-
Copy link

Andr3y- commented Mar 4, 2016

I have exactly the same problem:

import ObjectMapper
import RealmSwift

class WRUser: Object, Mappable {

    dynamic var ID: Int = 0
    dynamic var email: String = ""

    // MARK: - Init

    required convenience init?(_ map: Map) {
        self.init()
    }

    func mapping(map: Map) {
        ID <- map["user.id"]
        email <- map["user.email"]
    }

}

Actually building a project gives an error: Must call a designated initializer of the superclass "WRUser"

Any thoughts?

UPDATE:
The problem occurs only if I create a subclass of WRUser, say WRUserClient. As long as WRUser is a class that has no subclasses, the project compiles.

@nashirox did you subclass?

Any idea why does this happen?

@mrbagels
Copy link

Having same issue with a subclass of another mappable object. This issue says closed but there does not appear to be a solution?

@adipurnama
Copy link

Hi,
I also having same error when subclassing mappable object.
The working solution for me is by adding init method (same as parent class)

So, in above case :

class WRUserSubclass: WRUser {

    required convenience init?(_ map: Map) {
        self.init()
    }

    func mapping(map: Map) {
        // extended mapping here
    }
}

Hope this help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants