ios - Array of NSLocalizedStrings in Swift -
i attempting convert code swift stumbling code add nslocalizedstring
s array property. defined array array of string
s. i'm attempting add objects using +=
documentation states, receiving error could not find overload '+=' accepts supplied arguments
.
i'm sure it's simple mistake, i've tried few different combinations (appending as string[]
end, or after var name, or appending = []
declaration, etc) , cannot work. appreciate explanation of what's going on.
//property: var localizedtitles: string[] //in init: localizedtitles += [nslocalizedstring("my string", tablename: nil, bundle: nil, value: "my string", comment: "")]
i see 3 problems / comments:
for reason bundle parameter nslocalizedstring not optional. have provide actual bundle.
you must initialize array before trying append it.
you can define array array of strings since nslocalizedstring returns.
try (i added newlines make more readable in format):
var localizedtitles : [string] = [] localizedtitles += nslocalizedstring( "my string", tablename: nil, bundle: nsbundle.mainbundle(), value: "my string", comment: "" )
but because of parameters have default values, can do:
var localizedtitles : [string] = [] localizedtitles += nslocalizedstring("my string", value: "my string", comment: "")
Comments
Post a Comment