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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:56:51+00:00 2026-06-01T05:56:51+00:00

I am new to iOS and Objective-C, I already know that in a class,

  • 0

I am new to iOS and Objective-C, I already know that in a class, the class’s property you defined can only be initiated in an “instance” of that class.

But is there any mechanism in Objective-C that can store some data that can be used in the class’s class method?

To be specific, I’ m working on a quiet simple RPN Calculator app.

And according to the Stanford iOS Programming Dev(CS193P)’s tutorial, I create the RPN Calculator Controller’s model named RPNCalculatorBrain, and there’s a property (id)program, and a class method +(double)runProgram:(id)program.

(id)program is essentially an array contained all the operand and operation entered by user.

The instructor in that class suggest using class method so that other class (in this program’s situation, a functionGraphMVC) can pass (id)program to this class method and get the result of the program( or, the function). So that the model RPNCalculatorBrain can be made as generic as possible.

and there’s another class method +(double)runProgram:(id) program using:(NSDictionary*)variableValues. it is the variable edition of the above class method. So in case there’s a variable (X, a, b) in id(program), this class method can use (NSDictionary *)variableValues to interpret the variable’s value.

But Personally I want to improve this method, I was just wondering if I can store Calculator’s special operation (π, e) AND the variable (x) in my model (CalculatorBrain), and give a class method +(void)setXValue(); to whoever wants use it. So I can store everything about Calculation in my model. But as far as I know, I can’t store something that can be used in class method.

And store this information in NSUserDefault seems inappropriate, AND I have’t read the Documentation about Core Data yet.

I know my idea seems to be a lithe strange and naive, and I certainly can use some alternate approach to do the same job, but I just want to know whether it is possible. Thanks!

If my description confuse you guys, please forgive me! My writing english is …

  • 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-01T05:56:52+00:00Added an answer on June 1, 2026 at 5:56 am

    The usual approach to this is to create a static global variable in the implementation file of your class, then initialize it in the +initialize class method (see this question), or initialize it lazily in something analogous to a class-level property accessor.

    However, almost everything about the design you describe is questionable. If you really need a globally-accessible object with state, you could implement the Singleton pattern. Even then, dependency injection would be a better approach so you don’t couple yourself to one concrete implementation all over the place.

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

Sidebar

Related Questions

I'm new to objective-c and ios, but I'm coming along alright. Now I've run
I am new to RubyMotion for iOS app, but I coded using Objective C.
I am new iOS development but I know android at eclipse. For example I
I am fairly new to Objective C and iOS programming but am constantly trying
I am new in iOS objective c and now I build an app that
I am new to iOS/objective-C and I wanted to know how to build custom
I'm new to iOS and Objective-C. I have an application that displays a table
First of all, I am a a very new Objective C/Cocoa iOS Developer but
I'm new to iOS development and m curious to know how can i create
I am relatively new to Objective C/iOS development so I realize that this may

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.