@FetchRequest +不区分大小写的排序-SwiftUI和CoreData

问题描述

我有一个名称排序的项目列表。

我可以创建一个不区分大小写的提取请求,如下所示:

import pandas as pd
import numpy as np
paris_listing = pd.read_csv("C:../.../.../paris_airbnb.csv")
stripped_commas = paris_listing["price"].str.replace(",","")
stripped_dollars = stripped_commas.str.replace("$","")
paris_listing["price"] = stripped_dollars.astype("float")
mean_price = paris_listing.iloc[0:5]["price"].mean()
print (mean_price)

尽管我更喜欢这样做:

def conversion_price(price_conv):
    price_conv = price_conv.str.replace(","")
    price_conv = price_conv.str.replace("$","")
    price_conv = price_conv.astype("float")
    price_mean = price_conv.iloc[0:5].mean()
paris_listing["converted_price"] = paris_listing["price"].apply(conversion_price)

@FetchRequest是否可以将选择器作为参数?

从文档开始,NSSortDescriptor似乎接受了一个名为struct ContentView: View { var fetchRequest: FetchRequest<Item> init() { fetchRequest = FetchRequest<Item>(entity: Item.entity(),sortDescriptors: [NSSortDescriptor(key: "name",ascending: true,selector: #selector(Nsstring.caseInsensitiveCompare(_:))) ]) } var body: some View { // content } } 的参数,但我无法使其正常工作或在网上找到任何示例。

解决方法

您可以将NSString localizedStandardCompare方法传递给选择器属性:

NSSortDescriptor(key: "name",ascending: true,selector: #selector(NSString.localizedStandardCompare))