File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88
99#import < UIKit/UIKit.h>
1010
11- @class Feed;
12-
1311@interface CSSearchFeedCell : UITableViewCell
1412
1513#pragma mark - IBOutlets
1614
17- // The feed's icon
15+ // / The feed's icon
1816@property (weak , nonatomic ) IBOutlet UIImageView *imageView_icon;
1917
20- // The feed's name
18+ // / The feed's name
2119@property (weak , nonatomic ) IBOutlet UILabel *label_name;
2220
21+ // / The add feed action
22+ - (IBAction )addFeedToUser : (id )sender ;
2323
2424#pragma mark - Other Properties
2525
26- // The feed item this cell is based on
27- @property (nonatomic , weak ) Feed *feed;
26+ // The NSDictionary of the feed this cell is based on
27+ @property (nonatomic , weak ) NSDictionary *feed;
2828
2929@end
Original file line number Diff line number Diff line change 77//
88
99#import " CSSearchFeedCell.h"
10+ #import " Feed.h"
11+ #import " User.h"
1012
1113@implementation CSSearchFeedCell
1214
@@ -31,4 +33,20 @@ - (void)setSelected:(BOOL)selected animated:(BOOL)animated
3133 // Configure the view for the selected state
3234}
3335
36+ /* *
37+ * Add the feed to the user and save it in the database
38+ */
39+ - (IBAction )addFeedToUser : (id )sender {
40+ // Create a new Feed object and associated FeedItem objetcs
41+ Feed *newFeed = [Feed createOrUpdateFirstFromAPIData: self .feed];
42+
43+ // Add the feed to the currentUsers feeds
44+ User *currentUser = [User current ];
45+ NSMutableSet *mutableSet = [NSMutableSet setWithSet: currentUser.feeds];
46+ [mutableSet addObject: newFeed];
47+ currentUser.feeds = mutableSet;
48+
49+ // Save the feed and feed items in the database
50+ [[NSManagedObjectContext defaultContext ] saveToPersistentStoreAndWait ];
51+ }
3452@end
Original file line number Diff line number Diff line change @@ -96,6 +96,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
9696
9797 NSDictionary *searchedFeed = [self .sortedFeeds objectAtIndex: indexPath.row];
9898
99+ // Associate the feed to the cell
100+ cell.feed = searchedFeed;
101+
99102 // Set the label text
100103 cell.label_name .text = [searchedFeed objectForKey: @" name" ];
101104
Original file line number Diff line number Diff line change 229229 <state key =" normal" title =" +" >
230230 <color key =" titleColor" white =" 1" alpha =" 1" colorSpace =" calibratedWhite" />
231231 </state >
232+ <connections >
233+ <action selector =" addFeedToUser:" destination =" Vg0-Ic-Bi4" eventType =" touchUpInside" id =" vVw-rK-cbR" />
234+ </connections >
232235 </button >
233236 </subviews >
234237 </tableViewCellContentView >
You can’t perform that action at this time.
0 commit comments