0

I have this mapper:

import Foundation
import ObjectMapper

class Article: Mappable {
    var id: Int!
    var name: String!
    var image: String!
    var children: Article!

    required init?(_ map: Map) {
        mapping(map)
    }

    func mapping(map: Map) {
        id <- map["id"]
        name <- map["name"]
        image <- map["image"]
        children <- map["children"]
    }
}

and then i need to loop and find article by id:

func getArticleName(aid) {
    for article in articleList {
        if aid == article.id {
            return article.name
        }
        for child in article.children {
            if aid == child.id {
                return child.name
            }
        }
    }
    return ""
}

articleList is array of that Article mappable class.

Now when i loop in children, i get this error: Value of type 'Article' has no member 'Generator'

How can i loop in children array?

4
  • What's the question? Do you not understand that error message? Commented Sep 24, 2015 at 16:08
  • Yes, and how can i loop in children array? Commented Sep 24, 2015 at 16:08
  • 1
    It's not an array. That's what the error message is telling you. Commented Sep 24, 2015 at 16:09
  • Ohhh, my bad, forgot [], thanks.. Commented Sep 24, 2015 at 16:10

1 Answer 1

1

I don't know what ObjectMapper is, but the error message is simple enough. You are saying:

class Article: Mappable {
    var children: Article!
}

Thus, an article's children is an Article. So then when you say:

for child in article.children {

...the compiler stops you; an Article, which is what the children is, is not something about which you can say for ... in.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.