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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:38:11+00:00 2026-05-25T12:38:11+00:00

My model objects are lazy-loaded from an SQLite database. Don’t ask why, but the

  • 0

My model objects are lazy-loaded from an SQLite database. Don’t ask why, but the code uses QuickLite to populate the objects, which means that some housekeeping has to be performed before an accessor is used the first time.

I thought, naively, that valueForKey: and setValue:forKey: would be called by the @synthesize‘d accessors, so that I could simply overload those 2 methods to fill the object from the db, if necessary. Unfortunately, that doesn’t work: the @synthesize‘d accessors clearly don’t use KVC to get/set their represented value.

My question is therefore: Is there a way to call some code before any @property is accessed, without writing all getters/setters myself?

  • 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-25T12:38:12+00:00Added an answer on May 25, 2026 at 12:38 pm

    If your model objects were a subclass of NSManagedObject then your accessors would be using KVC (you declare the properties, then use ‘@dynamic’ rather than ‘@synthesize’ in the .m file to indicate that the accessors will be taken care of by other code).

    Basically it sounds like you’re re-implementing the faulting behaviour in Core Data.

    Based on your comment, the only way I can think of doing this would be to have a sort of proxy object which contains your actual object. So, your proxy object would have a single visible property, which is your actual object, and in the accessor for that, you would then check to see if you’d gone to the database for this particular object, if not, do your housekeeping.

    So, your calls would be

    NSString *someProperty = proxyObject.realObject.someProperty;
    

    Within proxyObject, the accessor for realObject:

    if (beenToTheDatabase)
        return realObject;
    else
    {
        // Do your business
        beenToTheDatabase = YES;
        return realObject;
    }
    

    Whether this is more or less effort than manually writing your accessors or migrating to core data, I don’t know.

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

Sidebar

Related Questions

I created model objects of from generating a scaffold, but now I want to
Below I call the same methods in author and w5 model objects. But one
Should model objects that go to the view be checked for null before going
I have some model objects I'm using in my Java client application. Later these
If I have Model.objects.all() I want to get only one object for any content_object=foo,
Oracle 11g version of ODP.Net introduces the provider model objects (session state provider, identity
I use django admin for my users to add their Model objects, as you
I'm using DataAnnotations attributes to validate my model objects. My model class looks similar
I am creating the domain model in my system. When designing my model objects,
In Eclipse RCP way of doing things, where should I keep my model objects?

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.