I'm taking as base this thread:
swift init not visible in objective-C
And I have the next class:
TokenModel.swift
public class TokenModel: NSObject, NSCoding, Codable {
required public init(usuario:String?, tokenSesion:String?, nombreCompleto:String?, cliente:String?, paises:[PaisModel]?) {
Usuario = usuario
TokenSesion = tokenSesion
NombreCompleto = nombreCompleto
Cliente = cliente
Paises = paises
}
public init(coder aDecoder: NSCoder) {
Usuario = aDecoder.decodeObject(forKey: "Usuario") as? String
TokenSesion = aDecoder.decodeObject(forKey: "TokenSesion") as? String
NombreCompleto = aDecoder.decodeObject(forKey: "NombreCompleto") as? String
Cliente = aDecoder.decodeObject(forKey: "Cliente") as? String
Paises = aDecoder.decodeObject(forKey: "Paises") as? [PaisModel]
}
public func encode(with aCoder: NSCoder) {
aCoder.encode(Usuario, forKey: "Usuario")
aCoder.encode(TokenSesion, forKey: "TokenSesion")
aCoder.encode(NombreCompleto, forKey: "NombreCompleto")
aCoder.encode(Cliente, forKey: "Cliente")
aCoder.encode(Paises, forKey: "Paises")
}
public var Usuario:String?
public var TokenSesion:String?
public var NombreCompleto:String?
public var Cliente:String?
public var Paises:[PaisModel]?
}
MyObjective.m
TokenModel * tm = [[TokenModel alloc] init];
There no methods (except aDecoder) are displayed
There, I have defined a simple method, who are implemented on Swift
.
But, at the moment to use it on my Objective-C
project, the only visible method is encode(with aCoder: NSCoder)
.
What other things I tried?
- I tried creating a
required public init()
(without parameters). - Deleting the
aDecoder
. - Creating a method
init(demo:NSString)
But, those methods are not appearing on my Objective C
class.
Does anyone know how I can import my custom init using Objective-C
?