Search code examples
iosswiftstructfbsdk

How to Handle Fetched User's Location from FBSDK IOS swift


i got the user Location using FBSDK. Now I do not know how to seperate the information to get each part of information i am printing it in console and this is what get

Optional({
id = 110855035610007;
name = "Rawalpindi, Pakistan";
})

how do i get "Rawalpindi" and "Pakistan" and store them in some variable according to Docs its returning a Struct i guess so i do not know how to handle that please guide me thanks


Solution

  • First thing, you have to create one responseDictionary and then store response in it.

    then you can get this name like,

     let str = self.responseDic.valueForKey("name") as? String
    

    Then you can separate this string like,

     let arr : NSArray = str!.componentsSeparatedByString(",") as NSArray
     print(arr.objectAtIndex(0))
     print(arr.objectAtIndex(1))
    

    Hope this way you will fix it.