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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:31:44+00:00 2026-05-17T22:31:44+00:00

I have a data model which is similar to this: (in another project) ________________________________

  • 0

I have a data model which is similar to this:

                                          (in another project)
 ________________________________        _______________________
|                                |      |                       |
|  Graph                         |      | DetailedGraph         |
|  GraphListener lstnr           |      | (needs to access foo) |
|  NSString foo                  | <----|_______________________|     
|  ____________________________  | 
| | GraphListener              | |       _______________________
| | Graph enclosing            | |      |                       |
| | (also needs to access foo) | |      | OtherClass            |
| |____________________________| |      | (cannot access foo)   | 
|________________________________|      |_______________________|

Now, my problem is, that GraphListener is supposed to be an inner class, which cannot be done in objc, so I have this solution:

@interface Graph_Listener
{
     @private
     Graph *enclosing;
}
@end

@interface Graph
{
    @package
    NSString *foo;
} 
@end

Now, my problem is, when I come to subclassing Graph, and making the DetailedGraph class, which is in another project, and still needs to access foo, How can I accomplish that (I would prefer not to use properties, because the variable foo shouldn’t be accessed outside of GraphListener and DetailedGraph.

  • 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-17T22:31:45+00:00Added an answer on May 17, 2026 at 10:31 pm

    First, I hope your two classes inherit from NSObject and are not root classes. Making a new root in Objective-C on iOS is actually quite difficult unless you keep your instances entirely in isolation from Foundation/UIKit.

    Two possible solutions:

    • Don’t access the iVar directly. Make and use the accessors, likely via an @property directive. This is the “more correct” solution in that a class implemented in library A should likely not be diddling the ivars of a class from library B directly. Going through the accessor better preserves encapsulation and acknowledges that direct iVar access is an extremely atypical pattern in Objective-C (largely limited only to a class accessing it’s own iVars directly).

    • Declare the iVars to be @public and diddle away. Fragile, atypical, and fraught with peril.


    Private in Objective-C really means “that compilation unit over there can’t see this declaration over here”.

    Thus, if you want, you can declare a property — say — to be publicly readonly and privately readwrite:

    Foo.h:

    @interface Foo....
    @property(readonly) int x;
    @end
    

    Foo+Private.h:

    @interface Foo()
    @property(readwrite) int x;
    @end
    

    Foo.m:
    #import “Foo+Private.h”
    @implementation Foo
    @synthesize x;
    @end

    Anything that imports Foo.h will only see that x is readonly. The implementation of Foo will see that it is readwrite. So will anything else that imports Foo+Private.h.

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

Sidebar

Related Questions

I have a Core Data model similar to this: Company Entity companyName attribute (string)
I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag]
i have this in my BlogRepository public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts() { var query = from
I have a data model where users have timelogs (which have dates). I'm trying
I have a data model that includes common columns like addedBy, editedby (user), addedDate,
My Techie Bretheren (and Sisteren, of course!), I have a LinqToSql data model that
I have a relationship in a Core Data model that feels like it wants
I have some configuration data that I'd like to model in code as so:
In my Core Data managed object model, I have an entity Foo with a
If I have the following: {hdrs: [Make,Model,Year], data : [ {Make:Honda,Model:Accord,Year:2008} {Make:Toyota,Model:Corolla,Year:2008} {Make:Honda,Model:Pilot,Year:2008}] }

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.