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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:34:01+00:00 2026-05-20T20:34:01+00:00

I have a potentially stupid question about a potentially stupid database design. Say I

  • 0

I have a potentially stupid question about a potentially stupid database design.

Say I have this design (in an iOS project using CoreData):

Class A
– name: NSString
– children: NSSet of Class A objects
– parent: Class A object

so it’s a simple parent/child setup. This is all fine.

Now, I want to make it so that if a Class A object doesn’t define a value for ‘name’, its parents are searched until one is found that does define ‘name’ and this value is returned.

This is a tricky thing to do, because my natural reaction was to override the getter for name like this:

- (NSString *)name
{
  return name =! nil ? name : self.parent.name;
}

but this doesn’t work because ‘name’ has to be accessed via self.name because this is a CoreData entity.

Then I had the idea of making a new method called nameRecursive which works like:

- (NSString *)nameRecursive
{
  return self.name =! nil ? self.name : self.parent.name;
}

but this feels very clunky and not very elegant (as the real life version of Class A has many properties which need to work like this), but I haven’t been able to think up anything nicer.

Does anyone have any thoughts on a) whether or not this is a stupid design or b) how I might solve it in an elegant way.

Any ideas or thoughts would be brilliant. 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-05-20T20:34:02+00:00Added an answer on May 20, 2026 at 8:34 pm

    It looks like the following question may help you implement the first method you mention

    How can I override a getter on a property when using Core Data?

    So instead of doing

    return name =! nil ? name : self.parent.name;
    

    You could do something like…

    return [self primitiveValueForKey:@"name"] =! nil ?
                         [self primitiveValueForKey:@"name"] : self.parent.name;
    

    Update to answer the query in the comments

    Apple recommends you do not do this. See the ‘Custom Attribute and To-One Relationship Accessor Methods’ section of the Apple documentation for Managed Object Accessor Methods. That provides more detail of how to do this properly (and encourages you not to.) Maybe if you have many properties that work in exactly the same way you could make a method such as

    recursiveValueFor: (NSString*) property;
    

    which can act as a generic wrapper around the recursion logic while not interfering with CoreData dynamic properties

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

Sidebar

Related Questions

I have a (potentially dumb) question about the C++ STL. When I make a
I have potentially large files that need to be sorted by 1-n keys. Some
I have an application where I have potentially many processes must send a message
I have an array of numbers that potentially have up to 8 decimal places
Problem: a table of coordinate lat/lngs. Two rows can potentially have the same coordinate.
I have a DataListItem which can potentially be a dropdownlist or a textbox. To
I have an objectdatasource that will return a potentially large collection (up to 200,000
If you have a situation where a TCP connection is potentially too slow and
how could I efficiently do collection membership checks in Javascript? I have a potentially
which is better, performance-wise, when you potentially have an empty list? if (_myList !=

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.