Swift初心者による初投稿です。
Twitter fabricを利用して、自分のTimelineを表示し、スワイプボタンで各カテゴリに分けることができるにしたいと思っております。
その際、CoreDataで保存した2種類の情報(ツイートIDと自分でタグ付けした値)の条件判定ができず、大変困っております。
Deleteボタンを押したツイートに関してはツイートのIDを保存し、CoreDataで保存したIDと照らし合わせて次回から表示にすることができたのですが、ツイートのIDとタグによる値付けをしたツイートに関しては2変数あり、どのようにすればうまくできるのかわかりません。
こちらのやり方が効率的ではないかもしれませんが、条件判定の仕方につき、ご教示いただけますと幸いです。どうぞ宜しくお願い致します。
swift
1<TimelineViewController.swift> 2 3 override func loadMore(cb: ()->(), errcb: ()->()) { 4 5 var params = ["result_type": "recent", "count":"35"] 6 7 TwitterAPI.getUserTL(params, tweets:{ 8 twttrs in 9 cb() 10 for tweet in twttrs { 11 // Deleteボタンを押したツイートを次回から非表示にする 12 if FunnelStore.sharedInstance.getStoredData(tweet.tweetID) != nil { 13 continue 14 } 15 // ここがおかしい。(スワイプボタンをタッチしたセルにfunnelTagで値をつけ、次回から非表示にしたい)どのようにすればよいのでしょうか。 16 if TagStore.sharedInstance.getStoredData(funnelTag, id: tweet.tweetID) != nil { 17 continue 18 } 19 //ここもおかしい。funnelTagで1,2,3と値を振って振り分けようとしてます 20 if TagStore.sharedInstance.getStoredData(2, id: tweet.tweetID) != nil { 21 continue 22 } 23 //ここもおかしい 24 if TagStore.sharedInstance.getStoredData(3, id: tweet.tweetID) != nil { 25 continue 26 } 27 28 self.tweets.append(tweet) 29 } 30 self.tableView.reloadData() 31 32 }, error: { 33 error in 34 self.alert = UIAlertController(title: error.localizedDescription , message: nil, preferredStyle: UIAlertControllerStyle.Alert) 35 self.alert!.addAction(UIAlertAction(title: NSLocalizedString("common_close" , comment: ""), style: UIAlertActionStyle.Cancel, handler: nil)) 36 self.presentViewController(self.alert!, animated: true, completion: nil) 37 errcb() 38 39 }) 40 } 41// 途中略 42 43 // UITableViewDelegate 44 45 46 func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? { 47 48 let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath) as? CustomTableViewCell 49 50 let funnelOne = UITableViewRowAction(style: .Normal, title: "funnel") { 51 (action, indexPath) -> Void in 52 53 tableView.setEditing(false, animated: true) 54 cell!.tag = 1 55 self.funnelTweet(cell!) 56 self.tweets.removeAtIndex(indexPath.row) 57 } 58 59 let funnelTwo = UITableViewRowAction(style: .Default, title: "funnel") { 60 (action, indexPath) -> Void in 61 62 tableView.setEditing(false, animated: true) 63 cell!.tag = 2 64 self.funnelTweet(cell!) 65 println("tag is \(cell!.tag)") 66 67 self.tweets.removeAtIndex(indexPath.row) 68 69 } 70
ご参考までにタグ付けのほうのCore Dataの一部も添付致します
swift
1<Core Data> 2 // check if a tweet id is in stored data 3 func getStoredData(funnelTag: Int, id:String) -> NSManagedObject? { 4 for obj: NSManagedObject in self.readDataList { 5 if funnelTag == obj.valueForKey("funnelTag") as? Int{ 6 return obj 7 } 8 if id == obj.valueForKey("funnelTag") as? String { 9 return obj 10 } 11 } 12 return nil 13 } 14func saveData(createdAt: NSDate, funnelTag: Int, id: String) { 15 // get managedObjectContext from AppDelegate 16 let appDelegate: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 17 let managedContext: NSManagedObjectContext = appDelegate.managedObjectContext! 18 // create new managedobject 19 let entity = NSEntityDescription.entityForName(self.entityName, inManagedObjectContext: managedContext) 20 let obj = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedContext) 21 obj.setValue(createdAt, forKey: "createdAt") 22 obj.setValue(funnelTag, forKey: "funnelTag") 23 obj.setValue(id, forKey: "id") 24 var error: NSError? 25 if !managedContext.save(&error){ 26 // println("Could not save \(error), \(error?.userInfo)") 27 } 28 // reload data 29 load() 30 } 31
あなたの回答
tips
プレビュー