I am declaring a array:
var array:[String] = []
assigning values:
array.append(uniqueId as String)
and then pass it to a function:
static var levels_array : [String] = []
class func setLevelsArray(arr:[String])
{
GamePrefrences.levels_array = arr
println(GamePrefrences.levels_array)
}
My problem is that when i print the array i get:
[Optional(88868658), Optional(112051080), Optional(95274974)]
Why is that optional? i only want Strings in the array so why is "optional" added?
I come from Java can someone explain why optional is created and how to remove it
Very likely the actual strings are "Optional(88868658)", etc. You have probably created this strings from an optional accidentally. In the above code, you definitely have an array of strings, not an array of optionals, and when you print an array of strings, they don't include the double-quotes (which can be confusing).
It may is happening here:
What type is
uniqueId
?as
is not used to convert types. It's just used to cast them if possible (though this should really fail if that's the case; so I'm suspecting you're doing a string interpolation somewhere).