Swift - Get list of countries

后端 未结 3 1535
抹茶落季
抹茶落季 2021-02-06 13:55

How can I get an array with all countries names in Swift? I\'ve tried to convert the code I had in Objective-C, which was this:

if (!pickerCountriesIsShown) {
           


        
3条回答
  •  太阳男子
    2021-02-06 14:25

    First of all ISOCountryCodes requires argument parenthesis so instead it would be ISOCountryCodes(). Second, you dont need parenthesis around NSLocale and ISOCountryCodes(). Also, arrayWithCapacity is deprecated meaning it is removed from the language. A working version of this would be somewhat like this

    if (!countriesPickerShown) {
        var countries = NSMutableArray()
        countries = NSMutableArray(capacity: (NSLocale.ISOCountryCodes().count))
    }
    

提交回复
热议问题