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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:06:00+00:00 2026-06-02T15:06:00+00:00

I have several NSFetchedResultsControllers throughout my app, and in every view controller, I implement

  • 0

I have several NSFetchedResultsControllers throughout my app, and in every view controller, I implement the respective delegate methods. However, instead of copying these delegate methods into every class that implements an NSFetchedResultsController, I thought I would just create a class that implements these delegate methods, and set all fetched results controller’s delegate to point to that one class. Here’s what I’ve tried, which doesn’t work:

Since the delegate methods need to know which table view they are making changes to, I thought I would just create a separate delegate class for each fetched results controller, and send a pointer to the tableview for that class:

FetchedResultsDelegate *delegate = [[FetchedResultsDelegate alloc] initWithTableView:parentTableView];
self.fetchedResultsController.delegate=delegate;
[delegate release];

However, this causes a BAD_ACCESS crash, so this means that I probably shouldn’t be doing what I’m doing above.

How can I create a single delegate class that handles all delegate requests for all my NSFetchedResultsControllers?

Edit: I was able to fix the problem by doing @property (nonatomic, retain) FetchedResultsDelegate *delegate; Is this ok? Some people are saying something about assign rather than retain?

  • 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-02T15:06:01+00:00Added an answer on June 2, 2026 at 3:06 pm

    Nothing is retaining your FetchedResultsDelegate as delegate properties are normally declared as assign. e.g. NSFetchedResultsController declares the delegate as

    @property(nonatomic, assign) id <NSFetchedResultsControllerDelegate> delegate
    

    Therefore you created the object and destroyed it straight away, but gave the fetchedResultsController a nasty dangling pointer.

    To fix this you need a retain on the delegate. So in your UITableViewController class add a new property

    // .h
    @property (nonatomic, strong) id<NSFetchedResultsControllerDelegate> tableViewDelegate;
    
    // .m
    @synthesize tableViewDelegate = _tableViewDelegate;
    

    then when you hook up you delegate just change your code to this

    FetchedResultsDelegate *delegate = [[FetchedResultsDelegate alloc] initWithTableView:parentTableView];
    self.fetchedResultsController.delegate = delegate;
    self.tableViewDelegate = delegate;
    [delegate release]; delegate = nil;
    

    Don’t forget

    Release this new ivar in the dealloc

    - (void)dealloc;
    {
        // ... other releases
        [_tableViewDelegate release];
        [super dealloc];
    }
    

    The use of assign is all about ownership semantics.

    In this case your UITableViewController should own the tableView’s delegate (e.g. strong/retain) as nothing else is.

    The reason that the NSFetchedResultsController uses assign and not retain/strong is because there is a good chance that the object that created it would act as the delegate, which would result in both objects owning each other (both having a retain held on each other), which causes a retain cycle

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

Sidebar

Related Questions

I have several questions about the Android in-app billing, as I cannot find what
I have several HTML pages that share a menu area. Every time I update
I have several view components in a layout. most of them have visibility=gone and
I have several methods, like below: - (void)methodA; - (void)methodB; - (void)methodC; and they
I have several pages to do with several table on each page. I've got
I have several complex data structures like Map< A, Set< B > > Set<
I have several thread pools and I want my application to handle a cancel
I have several bookmarked, but only have so much time in a day to
I have several textboxes where users can enter information into them. This can include
i have several classes with members called 'Id'. Originally i wanted to store these

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.