Swift instagram clone:正在加载关注的用户帖子

问题描述 投票:1回答:3

我正在尝试根据Ribbit tuto快速制作一个instagram克隆。人们可以共享照片并关注其他用户等。我使用Parse在用户之间建立了一个PFRelation。我现在想做的是显示在我的WalltableViewController中,只有关注的用户发布。

我制作了一个函数,将所有帖子加载到名为NSMutabletimeLineData数组中。

我什至在NSMutableArray中创建了一个功能来吸引关注的用户。

但是我用followedFriends未能成功过滤加载后功能。我遇到此错误:followedFriends,原因:Terminating app due to uncaught exception 'NSInvalidArgumentException'

这是我的代码:

'Cannot do a comparison query for type: __NSArrayM'
ios swift parse-platform nsmutablearray
3个回答
0
投票

FollowedFriends是一个数组,因此您需要使用 import UIKit import QuartzCore class WallTableViewController: UITableViewController, UINavigationControllerDelegate { @IBOutlet var posterAvatar: UIImageView! override func preferredStatusBarStyle() -> UIStatusBarStyle { return UIStatusBarStyle.LightContent } var timeLineData:NSMutableArray = NSMutableArray () var followedFriends:NSMutableArray = NSMutableArray () func loadUser () { followedFriends.removeAllObjects() var friendsRelation: AnyObject! = PFUser.currentUser().objectForKey("KfriendsRelation") var findUser : PFQuery = friendsRelation.query() findUser.findObjectsInBackgroundWithBlock { (objects:[AnyObject]!, error:NSError!) -> Void in if !(error != nil) { // The find succeeded. println("succesfull load Users") // Do something with the found objects for object in objects { self.followedFriends.addObject(object) println("users added to userlist") for item in self.followedFriends { println(item) } } self.tableView.reloadData() } else { // Log details of the failure println("error loadind user ") } } } func loadPost () { timeLineData.removeAllObjects() let currentUser = PFUser.currentUser() var findPost:PFQuery = PFQuery(className: "UserPost") findPost.whereKey("from", equalTo: followedFriends ) findPost.orderByDescending("createdAt") findPost.findObjectsInBackgroundWithBlock { (objects: [AnyObject]! , error: NSError!) -> Void in if !(error != nil) { // The find succeeded. println("current user post finded") // Do something with the found objects for object in objects { self.timeLineData.addObject(object) } self.tableView.reloadData() } else { // Log details of the failure println("error loadind user post") } } } override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return timeLineData.count } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell:WallTableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as WallTableViewCell let userPost:PFObject = self.timeLineData.objectAtIndex(indexPath.row) as PFObject //define the username var findUser:PFQuery = PFUser.query() findUser.whereKey("objectId", equalTo: userPost.objectForKey("from").objectId) findUser.findObjectsInBackgroundWithBlock{ (objects:[AnyObject]!, error:NSError!) -> Void in if !(error != nil) { if let user:PFUser = (objects as NSArray).lastObject as? PFUser { cell.usernameLabel.text = user.username // define avatar poster if let avatarImage:PFFile = user["profileImage"] as? PFFile { avatarImage.getDataInBackgroundWithBlock{(imageData:NSData!, error:NSError!)-> Void in if !(error != nil) { let image:UIImage = UIImage(data: imageData) cell.posterAvatar.image = image as UIImage cell.posterAvatar.layer.cornerRadius = 24 cell.posterAvatar.clipsToBounds = true } } } else { cell.posterAvatar.image = UIImage(named: "Avatar-1") cell.posterAvatar.layer.cornerRadius = 24 cell.posterAvatar.clipsToBounds = true } } } } //define the imagepost let imagesPost:PFFile = userPost["imageFile"] as PFFile imagesPost.getDataInBackgroundWithBlock{(imageData:NSData!, error:NSError!)-> Void in if !(error != nil) { let image:UIImage = UIImage(data: imageData) cell.imagePosted.image = image as UIImage } else { println("error") } } return cell } override func viewDidAppear(animated: Bool) { var currentUser = PFUser.currentUser() if (currentUser != nil) { println("User allready logued") } else { // Show the signup or login screen self.performSegueWithIdentifier("goToLogIn", sender: self) } } override func viewWillAppear(animated: Bool) { self.tableView.separatorColor = UIColor.whiteColor() tabBarController?.tabBar.tintColor = UIColor.whiteColor() self.loadUser() self.loadPost() self.tableView.reloadData() } } 。如果要与一个对象进行比较,请使用containedIn。更改为此。

equalTo

0
投票

我也建立了这个解决方案:

findPost.whereKey("from", containedIn:followedFriends)

0
投票

我可以获取instagram克隆吗?因为我是ios开发的新手,所以如果您与我分享它,我可以学到很多东西

© www.soinside.com 2019 - 2024. All rights reserved.