0
I have a class and a subclass inside
import Foundation
import ObjectMapper
class Aluno: Mappable
{
var ra:String!
var senha:String!
var nome:String!
var cpf:String!
var email:String!
var matricula:Matricula!
required init?(_ map: Map) {}
func mapping(map: Map) {
ra <- map["Ra"]
senha <- map["Senha"]
nome <- map["Nome"]
cpf <- map["Cpf"]
email <- map["Email"]
matricula <- map["Matricula"]
}
}
import Foundation
import ObjectMapper
class Matricula: Mappable
{
var turma:String!
var turno:String!
var curriculo:String!
var curso:Curso!
var instituicao:Instituicao!
required init?(_ map: Map) {}
func mapping(map: Map) {
turma <- map["Turma"]
turno <- map["Turno"]
curriculo <- map["Curriculo"]
curso <- map["Curso"]
instituicao <- map["Instituicao"]
}
}
After filling this object with a return from a JSON
Alamofire.request(.GET, urlBase, parameters: ["ra": idDoAluno, "senha": senhaDoAluno])
.responseJSON { response in
let JSON = response.result.value as! NSDictionary;
self.aluno = Mapper<Aluno>().map(JSON["Dados"]!)!
How do I save this Student object within a session (Nsuserdefaults) to retrieve it in another view?
You need to make your class conform to Nscoding http://stackoverflow.com/documentation/swift/5360/nscoding/19088/nscoding-compliant-class#t=2016081100544457751
– Leo Dabus
if it is to pass this data between sequential screens you can pass via screen startup parameters (init)
– Lucas Eduardo
I could demonstrate what that code would look like because I have a subclass Enrollment within the Student class
– Julio Figueiredo
http://stackoverflow.com/a/33194374/2303865
– Leo Dabus
So in this example the attributes of your class are all String, as would the code with a class that has another class as attribute??
– Julio Figueiredo