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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:08:03+00:00 2026-06-02T19:08:03+00:00

I have one Class called System it contains some variables and two arrays and

  • 0

I have one Class called “System” it contains some variables and two arrays and I need to access this from two other classes which should be able to read and write that variables
Im a total Beginner so its pretty possible that i already did some mistakes.

System.h

@interface System : UIViewController{

float length_of_one_hour; 
float length_of_first_break;
float length_of_second_break;
float length_of_lunch_break;
float length_of_shortned_hour;
float school_begin;

int school_end[5];
float school_length[5]; 

}

About_now.m

- (void)read_school_end_monday{

school_end_label.text=[NSString stringWithFormat:@"%i", school_end[0]];

}

Settings.m

- (IBAction)set_school_end_monday{

school_end[0]= [school_end_on_mondays_textfield.text intValue];

}

But i don’t know what to write in System.h and About_now.m that the variables are saved in System class and can be accessed from anywhere. And Yes I already tried @public and extern.
BTW I need to have an array for the school_end because I’ll calculate it (in use of length of an hour and when school actually starts etc.) with a function which already works but i need to access the variables from the About_now class afterwards.

Hope there is someone who can help me. 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-02T19:08:04+00:00Added an answer on June 2, 2026 at 7:08 pm

    A common way to share data across classes in iOS apps is by following the singleton pattern.

    SystemModel.h

    #import <Foundation/Foundation.h>
    
    @interface SystemModel : NSObject {
        @public
        float length_of_one_hour; 
        float length_of_first_break;
        float length_of_second_break;
        float length_of_lunch_break;
        float length_of_shortned_hour;
        float school_begin;
    
        int school_end[5];
        float school_length[5]; 
    }
    +(SystemModel*)instance;
    @end
    

    SystemModel.m

    @implementation SystemModel
    static SystemModel* _instance= nil;
    
    +(SystemModel*)instance {
        @synchronized([SystemModel class]) {
            if (!_instance)
                [[self alloc] init];
            return _instance;
        }
        return nil;
    }
    
    +(id)alloc {
        @synchronized([SystemModel class]) {
            return (_instance = [super alloc]);
    }
        return nil;
    }
    
    -(id)init {
        self = [super init];
        if (self != nil) {
            // your init code
        }
        return self;
    }
    
    @end
    

    Now you can use your instance like this:

     float tmp = [SystemModel instance]->length_of_one_hour;
    

    You could also convert instance variables to properties, and use the dot syntax. It does not matter for floats and arrays, but for id-based objects using properties is preferred.

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

Sidebar

Related Questions

I am having one class called BaseClass which contains some logic applicable to whole
I have three files: one called sql.php witch has a class db that I
I have a class User with one field called birthDate which is a java.sql.Date
I can't figure out why I'm getting this error. I only have one class
I have one abstract class and many child classes. In child classes are from
i have one single class for margin and i am using this class to
I have one grails application.In that I have one model class named Book. From
I have a new MVC3 project with one Controller called PublicController.cs which contains 4
I have a class called ItemBase from which a number of classes inherit. In
I need some help with using integer from one activity to another. I am

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.