I am kind stuck with the following.
I've got the following array
var selectedItems = Set<String>()
That has some items from parse inserted to it
self.selectedItems.insert(objectToAppend)
Then I've created the following variable where I intend to convert the Set into something I could use on my parse query with the following line. But almost nothing converts. [AnyObject, [String], [self.selectedHobbies], ["\(self.selectedHobbies)"]
... none works.
let itemsArray = self.selectedHobbies as [AnyObject]
And if I do not convert it I cannot use in the query bellow.
query.whereKey("itemTag", containedIn: itemsArray as [AnyObject])
If I could manage to convert it to a [String]
it would solve my problem. Not sure how.
A variable can be declared as String type by following the below syntax, Swift provides the function of integer initializers using which we can convert a string into an Int type. To handle non-numeric strings, we can use nil coalescing using which the integer initializer returns an optional integer.
Swift Set to Array. An NSSet can be converted to Array using set.allObjects() but there is no such method in the new Set (introduced with Swift 1.2). It can still be done by converting Swift Set to NSSet and use the allObjects() method but that is not optimal.
The toString function accepts any type and will always produce a string. If it’s a Swift type that implements the Printable protocol, or has overridden NSObject ’s description property, you’ll get whatever the .description property returns. In the case of NSNumber, you’ll get a string representation of the number.
The toString function accepts any type and will always produce a string. If it’s a Swift type that implements the Printable protocol, or has overridden NSObject ’s description property, you’ll get whatever the .description property returns.
When in doubt, try the init!
let selectedItems: Set<String> = ["One", "Two", "Three"]
let arr = [String](selectedItems)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With