使用locale swift解析查询字符串排序

时间:2015-04-20 12:16:47

标签: swift parsing sorting

我正在查询数据库,如下所示。但是,orderbyAscending无法正常工作,重音字母全部排在底部。 Parse有什么办法按地区进行排序吗?或者我必须在代码中排序?字符串数组不长,大约40个字。

  var query = PFQuery(className: RFIstanbulDistrictsClassKey)
  query.whereKey(RFIstanbulDistrictsDistrictKey, notEqualTo: "")
  query.orderByAscending(RFIstanbulDistrictsDistrictKey)

// constants are defined as follows:
// let RFIstanbulDistrictsClassKey = "IstanbulDistricts"
// let RFIstanbulDistrictsDistrictKey = "district"

1 个答案:

答案 0 :(得分:0)

事实证明我需要在从Parse加载数组后对其进行排序:

districts.removeAll(keepCapacity: true)
let query = PFQuery(className: RFIstanbulDistrictsClassKey)
query.whereKey(RFIstanbulDistrictsDistrictKey, notEqualTo: "")

query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
  if error == nil {

    districts = objects.map { String($0[RFIstanbulDistrictsDistrictKey] as! String) }
    districts.sort { return $0 < $1 } // sort ascending
  }
}