Dears,
this is my code testable in a playground:
import Foundation
import UIKit
enum Error : Swift.Error, LocalizedError {
case failedTypeCastingUITableViewCell(name: String, type: Any.Type, reuseIdentifier: String?)
var domain: String {
return ""
}
var code: Int {
return 0
}
var nserror : NSError {
return NSError(domain: self.domain,
code: self.code,
userInfo: self.userInfo)
}
// var userInfo : [String: Any]? {
// var userInfo : [String: Any] = [:]
//
// switch self {
// case .failedTypeCastingUITableViewCell(let name, let type, let reuseIdentifier):
// userInfo = [
// "param_name": name
// ,"param_type": "\(type)"
// ,"param_identifier": reuseIdentifier
// ]
// return userInfo
// }
// }
var userInfo : [String: Any]? {
var userInfo : [String: Any] = [:]
switch self {
case .failedTypeCastingUITableViewCell(let name, let type, let reuseIdentifier):
userInfo = [
"param_name": name
,"param_type": "\(type)"
]
userInfo["param_identifier"] = reuseIdentifier
return userInfo
}
}
}
print(Error.failedTypeCastingUITableViewCell(name: "", type: UITableViewCell.self, reuseIdentifier: nil).userInfo)
this is the result I get from print and is what I want to achieve with commented code:
Optional(["param_name": "", "param_type": "UITableViewCell"])
this is the result I get from commented code instead:
Optional(["param_identifier": nil, "param_type": "UITableViewCell", "param_name": ""])
I know It have to work this way, but my question is can I get rid of this in some way? ie. custom init? custom subscript?