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 9301421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:00:48+00:00 2026-06-18T23:00:48+00:00

I have this problem where I can’t think of how to write this predicate.

  • 0

I have this problem where I can’t think of how to write this predicate.

I have an Entity called Contact, it has a string property “pages”, let’s say

contact.pages = @"1,5,11,15,17";

There is a lot of contacts in my database, and I want to fetch only these contacts that contains a certain id. So let’s say I want to fetch only these contacts, which pages contains id @”1″.

I can think of something like this,

NSPredicate* predicate = [NSPredicate predicateWithFormat:@"self.pages CONTAINS %@", _pageId];

But my problem is that this would also get contacts, that e.g has pages = @”11,15″.

So any ideas on how to achieve that?
I would be grateful for any suggestions, thanks in advance!

  • 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-06-18T23:00:49+00:00Added an answer on June 18, 2026 at 11:00 pm

    The “MATCHES” operator of NSPredicate can be used to compare against a regular expression:

    NSString *pageId = @"1";
    NSString *regex = [NSString stringWithFormat:@"(.*,)?%@(,.*)?", pageId];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"pages MATCHES %@", regex];
    

    But you should also consider to replace the string property by a to-many relationship to a Page entity, then the predicate would look like

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY pages.pageid == %@", pageId];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem: I can write to a Postgis table with a geography
I have this problem: My web application has a form where the users can
I have this problem that I can ref a button for control it. I
I have had this problem crop up a few times and I can't figure
I have worked on this problem for my entire day and can't solve it.
I have a problem that I can't resolve. Let's say I have this map
I'm quite new to hibernate and have stumbled on this problem, which I can't
I have this code and can't figure out what seems to be the problem:
I can't fix this problem on my listview template: i have the error as
I hope some of you guys can help me with this problem.... I have

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.