Note that there are some explanatory texts on larger screens.

plurals
  1. POIf JSON response is "true", don't show results in Table View
    primarykey
    data
    text
    <p>I'm getting this JSON:</p> <pre><code>{ "timestamp": "2013-05-03T22:03:45Z", "resultsOffset": 0, "status": "success", "resultsLimit": 10, "breakingNews": [], "resultsCount": 341, "feed": [{ "headline": "This is the first headline", "lastModified": "2013-05-03T21:33:32Z", "premium": false, "links": { "api": { </code></pre> <p>And use this to load it in a UITableView:</p> <pre><code>@property (strong, nonatomic) NSArray *headlinesArray; - (void)viewDidLoad { [[RKObjectManager sharedManager] loadObjectsAtResourcePath:[NSString stringWithFormat:@"/now/?leafs=%@&amp;teas=%@&amp;apikey=xxxxx", leafAbbreviation, teaID] usingBlock:^(RKObjectLoader *loader) { loader.onDidLoadObjects = ^(NSArray *objects){ premiumArray = objects; [_tableView reloadData]; }; [loader.mappingProvider setMapping:[Feed mapping] forKeyPath:@"feed"]; loader.onDidLoadResponse = ^(RKResponse *response){ //NSLog(@"BodyAsString: %@", [response bodyAsString]); }; }]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"standardCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; Feed *feedLocal = [headlinesArray objectAtIndex:indexPath.row]; NSString *headlineText = [NSString stringWithFormat:@"%@", feedLocal.headline]; cell.textLabel.text = headlineText; return cell; } </code></pre> <p>Headline class model:</p> <pre><code>@property (strong, nonatomic) NSString *headline; @property (strong, nonatomic) Links *linksHeadline; </code></pre> <p>Is there any way to check if <code>premium</code> is <code>true</code> in the JSON, to not show the headline in the <code>UITableView</code>?</p> <p><strong>EDIT 1</strong> I added <code>@property (strong, nonatomic) NSArray *premiumArray;</code> which is pulling in the correct data associated with <code>premium</code>, so now I just need help looking thru that array for links that say <code>TRUE</code> so my <code>UITableView</code> won't show any headlines that premium = TRUE.</p> <p><strong>EDIT 2</strong> I posted the <code>viewDidLoad</code> code above.</p> <p><strong>EDIT 3</strong></p> <p>Feed.h</p> <pre><code>@property (nonatomic, strong) NSString *headline; @property (nonatomic, strong) NSString *premium; </code></pre> <p>Feed.m</p> <pre><code>+ (RKObjectMapping *)mapping { RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[self class] usingBlock:^(RKObjectMapping *mapping) { [mapping mapKeyPathsToAttributes: @"headline", @"headline", @"premium", @"premium", nil]; }]; return objectMapping; } </code></pre> <p><strong>EDIT</strong></p> <pre><code>I added this per some answers, but still couldn't get it working, any thoughts? @property (strong, nonatomic) NSArray *premiumArray; @property (strong, nonatomic) NSMutableArray *myMutable; [[RKObjectManager sharedManager] loadObjectsAtResourcePath:[NSString stringWithFormat:@"/now/?leagues=%@&amp;teams=%@&amp;apikey=5qqpgrsnfy65vjzswgjfkgwy", leagueAbbreviation, teamID] usingBlock:^(RKObjectLoader *loader) { loader.onDidLoadObjects = ^(NSArray *objects){ //sports = objects; premiumArray = objects; [_tableView reloadData]; }; [loader.mappingProvider setMapping:[Feed mapping] forKeyPath:@"feed"]; loader.onDidLoadResponse = ^(RKResponse *response){ //NSLog(@"BodyAsString: %@", [response bodyAsString]); }; }]; self.myMutable = [[premiumArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"premium = YES"]] mutableCopy]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload