我需要在 swift 5 中使用两个同名的类。为此,我在两个不同的模块中创建了这两个类,但我对如何在UIViewController
我的一堂课是Person
这是在models
> student
模块和另一个类是Person
与 是在models
module
我尝试过导入类
import class models.student.Person
class BookViewController: UIViewController {
var students:[Person] = [] //it should call models.student.Person
var people: [Person] = [] //it should call models.Person
...
但上面的 Person 类指向models.Person
只是,它并不指向models.student.Person
模型中的 Person 类 > Person.swift 是
import Foundation
// MARK: - Person
public struct Person: Codable {
public let firstName: String?
public let lastName: String?
public let address: String?
public let phone: String?
enum CodingKeys: String, CodingKey {
case firstName = "first_name"
case lastName = "last_name"
case address = "address"
case phone = "phone"
}
public init(firstName: String?, lastName: String?, address: String?, phone: String?) {
self.firstName = firstName
self.lastName = lastName
self.address = address
self.phone = phone
}
}
和 models.student.Person.swift 是
import Foundation
// MARK: - Person
public struct Person: Codable {
public let fullName: String?
public let educationalQualification: String?
public let college: String?
enum CodingKeys: String, CodingKey {
case fullName = "full_name"
case educationalQualification = "educational_qualification"
case college = "college"
}
public init(fullName: String?, educationalQualification: String?, college: String?) {
self.fullName = fullName
self.educationalQualification = educationalQualification
self.college = college
}
}
我需要我的课程BookViewController
我无法将类名更改为不同的类名,我应该使用相同的类名。