0
排序像(AZ,0-9和特殊字符),我试图梳理如何JSON字典数组值斯威夫特
let students: NSMutableArray = [["fullName": "23412334", "number": "39485793"],["fullName": "&[email protected]", "number": "395793"],["fullName": "Abena", "number": "3572343"],["fullName": "Peter", "number": "394568993"],["fullName": "Kweku", "number": "309693"]]
let sortDescriptor = NSSortDescriptor(key: "fullName", ascending: true, selector: #selector(NSString.localizedCompare(_:)))
let sortedResults: NSArray = students.sortedArray(using: [sortDescriptor]) as NSArray
students = NSMutableArray(array: sortedResults)
print(students)
// Output:
(
{
fullName = "&[email protected]";
number = "395793";
},
{
fullName = "23412334";
number = "39485793";
},
{
fullName = "Abena";
number = "3572343";
},
{
fullName = "Kweku";
number = "309693";
},
{
fullName = "Peter";
number = "394568993";
}
)
但我需要:
// Output:
(
{
fullName = "Abena";
number = "3572343";
},
{
fullName = "Kweku";
number = "309693";
},
{
fullName = "Peter";
number = "394568993";
},
{
fullName = "23412334";
number = "39485793";
},
{
fullName = "&[email protected]";
number = "395793";
},
)
请帮助我如何这个排序....感谢你非常提前....
你的宣言。在你的[前一个问题]溶液(https://stackoverflow.com/questions/45277831/the-array-value-should-be-sort样字母,数字,和特殊字符)。顺便说一句:不要在Swift中使用'NSMutable ...'集合类型。它们缺少类型信息,并且与Swift本机类型无关。 – vadian
是的..我尝试过,但没有工作....请帮助我@vadian –