Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class func showFeed(completion: @escaping ([Feed]) -> Swift.Void){
- let token = UserDefaults.standard.string(forKey: "token")
- let params: [String: String] = ["user_token": token!]
- var feeds = [Feed]()
- Alamofire.request(Api.GetFeeds, method: .post, parameters: params).responseJSON { (response) in
- switch response.result{
- case .success(let data):
- let json = JSON(data)
- for index in 0...json.count-1 {
- let aObject = json[index]
- var type = FeedType.text
- if(aObject["product_preview"]).exists(){
- type = .product
- }
- var mood = ""
- if aObject["mood"].exists(){
- mood = aObject["mood"].string!
- }
- var images=[String]()
- if aObject["file:wallphoto"].exists(){
- type = .picture
- }
- let guid = aObject["guid"].string!
- let owerId = aObject["owner_guid"].string!
- let timestamp = aObject["time_created"].string!
- let description = aObject["description"].string!
- let desJson = JSON(parseJSON: description)
- let text = desJson["post"].string!
- var friendTagId = ""
- if desJson["friend"].exists(){
- friendTagId = desJson["friend"].string!
- }
- var location = ""
- if desJson["location"].exists(){
- location = desJson["location"].string!
- }
- let likes = aObject["likes"].string!
- let comments = aObject["comments"].string!
- print("[Feed] status", text)
- var owner:User?
- var friendTag:User?
- User.info(forUserId: owerId, completion: { (user) in
- owner = user
- print("[Feed] info: ", owerId)
- User.info(forUserId: friendTagId, completion: { (userTag) in
- friendTag = userTag
- print("[Feed] info tag: ", friendTagId)
- let feed = Feed(id: Int(guid)!, owner: owner!, type: type, timestamp: Int(timestamp)!, text: text, tagFriend: friendTag!, location: location, mood: mood, images: images, likes: likes, comments: comments)
- feeds.append(feed)
- print("[Feed] count: ",feeds.count)
- })
- })
- }
- completion(feeds)
- case .failure(let error):
- print("Error: ", error)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement