我試圖在代碼生成當前區域設置屬性表,也碰到了問題,試圖給一個變量的值傳遞給函數:使用價值
let currentLocale = Locale(identifier: "en_US")
let calendar1 = currentLocale.calendar // "gregorian (fixed)"
let propertyName = "calendar"
let calendar2 = currentLocale.propertyName // Error: Value of type 'Locale' has no member 'porpertyName'
在上面的代碼最後一行,Locale的實例認爲我將它傳遞給「propertyName」而不是變量「calendar」的內容。
有沒有辦法將propertyName(「calendar」)的值傳遞給Locale的實例?我知道在其他語言中,可以預先設置變量名稱,如'$ propertyName',並告訴它讀取變量的值。
如果可能,我想保留這個純粹的Swift。
你沒有調用帶參數的函數。 –