Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4273632
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:44:20+00:00 2026-05-21T07:44:20+00:00

I need to select stories from a NSArray of XML by matching a string

  • 0

I need to select stories from a NSArray of XML by matching a string from an XML element against a list of strings in another NSArray

The XML contains stories, each story has three criteria, say ‘Fruit’, ‘Veg’, ‘Spice’, each containing a single phrase. A sample story might look like:

<story>
    <title>I love cooking</title>
    <fruit>Oranges</fruit>
    <veg>Cauliflower</veg>
    <spice>Mixed spice</spice>
    <blurb>losts of text and stuff....</blurb>
</story>

I have three dictionaries of key/value pairs in a NSMutableDictionary generated from a pList

<Fruit:dictionary>
    'Ripe bananas' : 1
    'Green bananas' : 0
<Veg:dictionary>
    'Green beans' : 1
    'Cauliflower' : 0
<Spice:dictionary>
    'Nutmeg' : 1
    'Mixed spice' : 0

I don’t know what the keys will be, and I need to match the tag in the story against the keys.

i.e. story fruit tag:’Ripe bananas’ MATCHES ‘Ripe bananas’ in list of fruit keys

I can build three arrays of the keys using

NSMutableDictionary *fruitTagsDict = [prefsDictionary objectForKey:@"Fruits"];
NSArray *fruitTags = [fruitTagsDict allKeys];

I loop through the story XML extracting a tag

for (id myArrayElement in storyArray) {
    NSString *fruitString = [NSString stringWithString:[myArrayElement fruit]];
    //BOOL isTheObjectThere = [issueTags containsObject:fruitString];

    NSString *vegString = [NSString stringWithString:[myArrayElement veg]];

    NSString *spiceString = [NSString stringWithString:[myArrayElement spice]];

    //if ([[fruitTags objectAtIndex:row] isEqualToString:fruitString]) {
    //NSLog(@"Yo %@", fruitString);
            // ADD TO A NEW ARRAY OF MATCHING STORIES
    //}
        // Fails because row is undeclared
}

Then I start to glaze out.

The isTheObjectThere line produces nil then crashes at end of loop

I’ve looked at:
Filter entire NSDictionaries out of NSArray based on multiple keys
Making the Code check to see if the Text in a Text box matches any of the Strings in an NSArray

It seems predicate is the answer but frankly I getting confused.

What I need to do in metacode

repeat with stories
    if storyFruitTag is in fruitTagArray 
    OR storyVegTag is in vegTagArray 
    OR storySpiceTag is in spiceTagArray
        Add to new array of matching stories

Hopefully I’ve explained enough to get some pointers, I looked into NSMutableSet and Intersect (Xcode: Compare two NSMutableArrays) but the power of too much information got to me

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:44:21+00:00Added an answer on May 21, 2026 at 7:44 am

    Here’s a simple way to determine whether there are matches using key paths:

     if ([prefsDict valueForKeyPath:[NSString stringWithFormat:@"Fruit.%@", storyFruitTag]] ||
         [prefsDict valueForKeyPath:[NSString stringWithFormat:@"Veg.%@", storyVegTag]] ||
         [prefsDict valueForKeyPath:[NSString stringWithFormat:@"Spice.%@", storySpiceTag]]) {
           // one of the story's tags matches a key in one of the corresponding dictionaries
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to select a top row for each category from a known set
how can i express in xpath a) need select elements which contains specified keyword.
I need a select from table which does not have column that tells when
I need to select and act on a table element with JQuery, but only
I need to select multiple records I use SELECT * FROM `table` WHERE `ID`
I need help converting this SQL statement, into EF4: Select Posts.PostID, Post, Comment from
I need to be able to group the postcodes from Aus_Postcodes in this select
I need to select data when a page is viewed and update the 'views'
I need to select a bunch of data into a temp table to then
I need the Select Data Source dialog added to my application so that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.