Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如我有
[ ["A",1] ["B",5] ["C",3] ]
我如何对其进行排序,以便它以最高到最低的值 B、C、A 返回
您可以通过以下方式进行:
a.sort { return $0.last as! Int > $1.last as! Int }
不要忘记在使用此代码时添加额外的检查,最后一项不是整数或数组不是预期格式的情况。否则会导致崩溃。