セレクタからインスタンス名へのセレクタ。Unrecongnizedセレクタ名
セクションからpartion配列を作成したいと思います。私は速い2でこれをやろうとしているが、私はそれを働かせることができない。
var currentCollation : UILocalizedIndexedCollation!
var sections: [Section] {
let selector: Selector = "name"
let users: [User] = array.map { name in
let a = name["fullName"] as? String
let b = name["email"] as! String
let c = name["mobile"] as! String
let d = name["img"] as! String
let user = User(name: a!)
user.email = b
user.mobile = c
user.img = d
user.section = UILocalizedIndexedCollation.current().section(for: user, collationStringSelector:"name")
return user
}
var sections = [Section]()
for _ in 0..<currentCollation.sectionIndexTitles.count {
sections.append(Section())
}
for user in users {
sections[user.section!].addUser(user: user)
}
print(sections)
for section in sections {
print(section.users)
var user = section.users as? User
print(user?.name)
section.users = self.currentCollation.sortedArray(from: section.users, collationStringSelector: "name") as! [User]
}
return sections
}
@objc class User: NSObject {
let name: String
var section: Int?
var img: String?
var email: String?
var mobile : String?
init(name: String) {
self.name = name
}
}
class Section {
var users: [User] = []
func addUser(user: User) {
self.users.append(user)
}
}
「名前」と呼ばれるメソッドはありますか? –
エラーに関する質問を投稿するときは、必ず完全で正確なエラーメッセージを含め、エラーの原因となった行を指摘してください。 – rmaddy