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

  • Home
  • SEARCH
  • 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 686421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:01:22+00:00 2026-05-14T02:01:22+00:00

I’m trying to access a relationship (one to many) programatically. My Data model contains

  • 0

I’m trying to access a relationship (one to many) programatically.
My Data model contains an NSManagedEntity called language (with a two string attributes)
with a relationship to an entity called WordCategory (one-to-many).
I use an NSFetchRequest to get all the Language entities. that works fine.
I get the valueForKey for the relationship and that works fine. I can work with its objects. However, when I try to send the message count to the NSSet that stores the
WordCategory objects I get a

In other words, this line works:

       NSLog(@"word category count %@",[[wordCategory anyObject] valueForKey:@"name"]);

This one doesn’t:

NSLog(@"word category count %@",[wordCategory count]

I get a the message: EXC_BAD_ACCESS in the debugger.

Here’s the rest of the code:

NSManagedObjectContext *moc = [myAppDelegate managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Language" inManagedObjectContext:moc]];

NSError *error = nil;
NSArray *results = [moc executeFetchRequest:request error: &error];
if (error) {
    [NSApp presentError:error];
    return;
}

NSManagedObject *obj = [results objectAtIndex:0];
NSSet *wordCategory = [obj valueForKey:@"category"];
NSLog(@"word category count %@",[wordCategory count]);

I’ll appreciate any light than anybody can shed in this mystery. Thanks for your help!

  • 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-14T02:01:23+00:00Added an answer on May 14, 2026 at 2:01 am
    • (NSUInteger)count

    The return type of the method count on NSSet is NSUInteger. So if you try to use %@ to refer to this type, you will get the message: EXC_BAD_ACCESS in debugger. You are accessing a type of value that is not expected.

    Try using %d instead.

    NSLog(@”word category count %d”,[wordCategory count]);

    Edited after bobDevil’s comment (Accurate answer – more in comments):

    NSLog(@”word category count %lu”,[wordCategory count]);

    All the best.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

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.