ios - Array of NSLocalizedStrings in Swift -


i attempting convert code swift stumbling code add nslocalizedstrings array property. defined array array of strings. 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:

  1. for reason bundle parameter nslocalizedstring not optional. have provide actual bundle.

  2. you must initialize array before trying append it.

  3. 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

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -