Функция из базового класса
open class ResultBase: ParametersBase<ResultBase.Fields, ResultBase>
{
public enum Fields
{
case Value
case Status
case Message
case ErrorMessages
case WarningMessages
case SuccessMessages
}
private var responseValue: Any?
public var status = CoreResponseStatus.ok
public var message: String?
public var errorMessages = [CoreResponseBase]()
public var warningMessages = [CoreResponseBase]()
public var successMessages = [CoreResponseBase]()
func from(dictionary: [AnyHashable: Any])
{
set(dictionary: dictionary)
responseValue = value(forKey: .Value)
if let value:Int = value(forKey: .Status) {
status = CoreResponseStatus(rawValue: value) ?? CoreResponseStatus.ok
}
message = value(forKey: .Message)
if let value:[[AnyHashable:Any]] = value(forKey: .ErrorMessages) {
value.forEach { [weak self] (item) in
self?.errorMessages.append(CoreResponseBase().from(dictionary: item))
}
}
if let value:[[AnyHashable:Any]] = value(forKey: .WarningMessages) {
value.forEach { [weak self] (item) in
self?.warningMessages.append(CoreResponseBase().from(dictionary: item))
}
}
if let value:[[AnyHashable:Any]] = value(forKey: .SuccessMessages) {
value.forEach { [weak self] (item) in
self?.successMessages.append(CoreResponseBase().from(dictionary: item))
}
}
}
func toDictionary() -> [AnyHashable: Any]
{
toDictionary = [AnyHashable: Any]()
add(key: .Value, value: responseValue)
add(key: .Status, value: status.rawValue)
add(key: .Message, value: message)
var errorMessages = [[AnyHashable: Any]]()
for item in self.errorMessages
{
errorMessages.append(item.toDictionary())
}
add(key: .ErrorMessages, value: errorMessages)
var warningMessages = [[AnyHashable: Any]]()
for item in self.warningMessages
{
warningMessages.append(item.toDictionary())
}
add(key: .WarningMessages, value: warningMessages)
var successMessages = [[AnyHashable: Any]]()
for item in self.successMessages
{
successMessages.append(item.toDictionary())
}
add(key: .SuccessMessages, value: successMessages)
return toDictionary
}
}
Функция из суперкласса
open class AuthenticationService
{
open class Authenticate: ParametersBase<Authenticate.Fields, Authenticate>
{
public enum Fields
{
case Expires
case LoginName
case Password
}
public var expires: String?
public var loginName: String?
public var password: String?
override open func from(dictionary: [AnyHashable: Any]) -> Authenticate
{
set(dictionary: dictionary)
let ret = Authenticate()
ret.expires = value(forKey: .Expires)
ret.loginName = value(forKey: .LoginName)
ret.password = value(forKey: .Password)
return ret
}
open func toDictionary() -> [AnyHashable: Any]
{
toDictionary = [AnyHashable: Any]()
add(key: .Expires, value: expires)
add(key: .LoginName, value: loginName)
add(key: .Password, value: password)
return toDictionary
}
}
open class AuthenticateResponse: ResultBase
{
public var value: AuthToken?
open override func from(dictionary: [AnyHashable: Any]) -> AuthenticateResponse
{
super.from(dictionary: dictionary)
let ret = AuthenticateResponse()
if let value:[AnyHashable:Any] = value(forKey: .Value)
{
ret.value = AuthToken().from(dictionary: value)
}
return ret
}
}
}
Здесь я хочу создать объект baseClass let ret = AuthenticateResponse () и вернуть значение из ret объект не из супер или себя. В текущем случае ret возвращает назначенное по умолчанию значение, а не значение словаря, но я хочу получить значения словаря от объекта ret.