I am trying to walk an object with alamofire, and everything is fine until I have to deal with the array of dictionaries that I have within that same object. I think I have a problem with the model, but I'm not sure and since I did not find any documents I decided to ask.
Model class:
import UIKit
import RealmSwift
import ObjectMapper
class Constelation : Mappable {
\ aqui el typalias lo creo para intentar parsear el array de diccionario
typealias dictionary = [[String : String]]
var itemId : String?
var name : String?
var subtitle : String?
var body : String?
var imagen : String?
var poster : String?
\ aqui stars me da un error diciéndome que no conforma el protocolo RealmCollectionValue
var stars = List<Stars>()
var objects : Array<dictionary>?
required init?(map: Map) {
}
func mapping(map: Map) {
itemId <- map["itemId"]
name <- map["name"]
subtitle <- map["subtitle"]
body <- map["body"]
imagen <- map["imagen"]
poster <- map["poster"]
stars <- map["stars"]
objects <- map["objects"]
}
}
class Stars: Constelation {
@objc dynamic var nameStarst: String?
required convenience init?() {
self.init()
}
}
The ViewController class:
import UIKit
import Alamofire
import AlamofireImage
import AlamofireObjectMapper
class ViewController: UITableViewController {
var constellations: [Constelation]?
var stars: [Stars]?
@IBOutlet var table: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.setupUI()
self.setupData()
}
func setupUI() {
self.table.delegate = self
self.table.dataSource = self
}
func setupData() {
APIController.requestConstelations { (constellationArray, error) in
print("Terminé de sacar url \(constellationArray?.first?.imagen)")
print("saco el item \(constellationArray?.first?.itemId)")
if error != nil {
print("error")
}
else {
print()
for x in Stars {
print(x)
}
}
}
}
}
When I try to print the array it gives me nil or the value of the reference in memory. Is the question whether I have to create a property in the data model or is it using the constellation class and some protocol?
Thanks in advance.