@@ -49,9 +49,11 @@ - (void)viewDidLoad
4949 [super viewDidLoad ];
5050 self.currentUser = [User current ];
5151 self.feeds = [[NSMutableSet alloc ] init ];
52+
53+ // Setup the user and search datasources
5254 [self setUpDataSources ];
5355
54- // Setup feedSearch API
56+ // Setup feedSearch API requestor
5557 feedSearcher = [[CSFeedSearcher alloc ] init ];
5658
5759 // Set tableViewStyle
@@ -81,6 +83,8 @@ - (void)viewDidLoad
8183 for ( Feed *feed in addedFeeds ){
8284 [[self feeds ] addObject: feed];
8385 }
86+
87+ // Update and switch to the userFeed data source
8488 self.tableView_feeds .dataSource = userFeedDataSource;
8589 [userFeedDataSource updateWithFeeds: self .feeds];
8690
@@ -104,7 +108,10 @@ - (void)viewDidLoad
104108
105109- (void )setUpDataSources
106110{
111+ // Lists feeds in the database
107112 userFeedDataSource = [[CSMenuUserFeedDataSource alloc ] init ];
113+
114+ // Lists feeds returned by the search API
108115 searchFeedDataSource = [[CSMenuSearchFeedDataSource alloc ] init ];
109116}
110117
@@ -129,6 +136,8 @@ - (void)menuStateEventOccurred:(NSNotification *)notification {
129136 weakSelf.textField_searchInput .text = @" " ;
130137 [weakSelf.tableView_feeds setEditing: NO animated: YES ];
131138 weakSelf.menuContainerViewController .panMode = MFSideMenuPanModeDefault;
139+
140+ // Reset to the users feeds
132141 weakSelf.tableView_feeds .dataSource = userFeedDataSource;
133142 [weakSelf.tableView_feeds reloadData ];
134143 break ;
@@ -137,11 +146,17 @@ - (void)menuStateEventOccurred:(NSNotification *)notification {
137146
138147- (void )searchFieldDidChange
139148{
149+ // If the searchInput has text
140150 if (self.textField_searchInput .text && self.textField_searchInput .text .length > 0 ){
151+
152+ // Create empty searchFeed set
141153 NSMutableSet *searchedFeeds = [[NSMutableSet alloc ] init ];
154+
155+ // Switch to the searchFeed datasource and update the table
142156 [searchFeedDataSource updateWithFeeds: searchedFeeds];
143157 self.tableView_feeds .dataSource = searchFeedDataSource;
144158
159+ // If the user is typing a url
145160 if ([self .textField_searchInput.text hasPrefix: @" http" ]){
146161 // Get the local context
147162 NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread ];
@@ -151,15 +166,20 @@ - (void)searchFieldDidChange
151166 customFeed.name = self.textField_searchInput .text ;
152167 customFeed.url = self.textField_searchInput .text ;
153168
169+ // Add custom feed to the searchFeeds
154170 [searchedFeeds addObject: customFeed];
155171 }
156172 else {
173+ // Return feeds from the API similar to user input
174+ // Add these feeds to the searchFeed datasource
157175 [feedSearcher feedsLike: self .textField_searchInput.text];
158176 }
159177
178+ // Reload the table with new searchFeeds
160179 [self .tableView_feeds reloadData ];
161180 }
162181 else {
182+ // Switch to the userFeeds datasource
163183 self.tableView_feeds .dataSource = userFeedDataSource;
164184 [self .tableView_feeds reloadData ];
165185 }
0 commit comments