swift2 - converting AnyObject to Array list of Strings in swift -
i'm new swift , i'm extracting data parse
database. data column stored array in database managed extract anyobject
, want display each item. anyobject
displaying 1 entry instead of array list
class peopletable: uitableviewcontroller { //let textcellidentifier = "textcell" //var window: uiwindow? //let emptyarray: [anyobject] = [] var userfriends: [anyobject] = [] override func viewdidload() { super.viewdidload() queryfortable() print(userfriends) } func queryfortable() { let relationquery = pfquery(classname:"user_info") relationquery.wherekey("userid", equalto:"id123") var userfrnds = try? relationquery.findobjects() eachfriend in userfrnds! { self.userfriends.append(eachfriend["friends"]) } }
print(userfriends)
command out put :
[( rudzani, terrence, thendelano, "big-t", smallboy )]
i want out put :
rudzani, terrence, thendelano, "big-t", smallboy
how convert anyobject
array
list of strings
userfriends
array in array, printed output of type [[string]]
.
var userfriends = []
then inner array
let users = userfriends[0]
and join items
let users = userfriends[0].joinwithseparator(", ")
as type distinct, further type casting not needed.
edit: have cast type after retrieving object
do { let userfrnds = try relationquery.findobjects() eachfriend in userfrnds { self.userfriends.append(eachfriend["friends"] as! [string]) } } catch let error nserror { print(error) }
Comments
Post a Comment