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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:25:42+00:00 2026-06-07T18:25:42+00:00

I have been doing some reading and a little bit confused, let me explain.

  • 0

I have been doing some reading and a little bit confused, let me explain.

My situation:

ClassA.h has some arrays, and ClassA.m has some methods that uses these arrays. I also have ClassB, ClassC, ClassD… that have their own arrays, and their own methods that use these arrays. Up until now I have just been copying and pasting the code into each class.

What I want to do:

I did some reading and found that I want to create a parent class, where all the methods are housed, and then use these methods in my classes:

//parentClass.m
@implementation parentClass

+ (void)commonMethod:(id)sender{

...

}

@end


//classA.m

@implementation classA

- (void)someMethod{
    [parentsClass commonMethod];
}

@end


//classB.m

@implementation classB

- (void)someMethod{
    [parentClass commonMethod];
}

@end

The Problem:

So I moved the methods to the parentClass.m, and the arrays to the parentClass.h. My problem is when I try to build and run, I get errors like Instance variable <someArray> accessed in class method. I am not sure what to do. Is the only way around this problem to declare my arrays above the @interface in the .h file?


EDIT: The reason I want to use this technique for using methods in the parent class is because I would like to call the methods like this:

[commonClass commonMethod];

And not have to declare an instance of the parent class every time.

THANKS!

  • 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-07T18:25:44+00:00Added an answer on June 7, 2026 at 6:25 pm

    Regardless of inheritance, you have to use instance methods (and not class methods) if you want to access instance variables, like your array. An instance method is indicated by a - (minus) before the method signature, while class methods use a +.

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

Sidebar

Related Questions

Right, bit of a strange question; I have been doing some linq to XML
I have been doing some reading and have found out that the Java Swing
I have been doing some catching up lately by reading about cloud hosting. For
I have been doing a little reading on Flow Based Programming over the last
I have been doing some reading, and I see that I can use getch()
I have been doing some reading lately one article I read was from Opera.
I have been doing some reading in preparation for starting my first WCF project
I've been doing some reading recently and have encountered the Law of Demeter. Now
I have been doing some reading on this subject, but I'm curious to see
I've been doing some javascript reading, and I've gathered that a closure has access

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.