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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:24:08+00:00 2026-06-17T21:24:08+00:00

The following array x is not large, but it is my example array. float

  • 0

The following array x is not large, but it is my example array.

float x[4] = {1.0f, 2.0f, 4.0f, 8.0f};

Say, I want to use the array in my ViewController BSViewController.h/.m . I have included BSParam.h in BSViewController.h, but I don’t know what else to do to use x in BSViewController.m

Below is the code so far for my class which will containt my constant arrays.

//
//  BSParam.h

#import <Foundation/Foundation.h>

@interface BSParam : NSObject

@end



//
//  BSParam.m

#import "BSParam.h"

@implementation BSParam

#include <stdio.h>


float x[4] = {1.0f, 2.0f, 4.0f, 8.0f};

@end
  • 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-17T21:24:09+00:00Added an answer on June 17, 2026 at 9:24 pm

    1) If you want to make it available outside of your class, use the extern keyword to make it available:

    //  BSParam.h
    extern float x[4];
    
    
    //  BSParam.m
    #import "BSParam.h"    
    float x[4] = { 1.0f, 2.0f, 4.0f, 8.0f };
    
    // BSViewController.m
    #import "BSParam.h"
    
    - (void)dummy {
      float t = x[0]; // etc.
    }
    

    2) Anyhow, this solution will make the variable x global, and available anywhere in your application, without any context/namespace to access it, so that’s not the optimal solution.

    To make global values accessible to other parts of your application, you better use the Singleton pattern, or use a class method for that.

    For example:

    @interface BSParam : NSObject
    +(float[4])x;
    @end
    
    @implementation BSParam
    +(float[4])x {
        return (float[4]){ 1.0f, 2.0f, 4.0f, 8.0f };
    }
    @end
    

    So that you can use [BSParam x] to access your array, instead of just x, adding some namespace to access this x array, avoiding the risk to mess with other local variables or whatever.

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

Sidebar

Related Questions

I have the following code. I am not sure why the myData array is
I have a large data set and i want to convert it into array.
I have the following array: $franchise_a_status[] = array( 'id' => $franchise['franchise_id'], 'text' => $franchise['franchise_surname'].
I have the following array(in python): arr= ['\n', ' a#B\n', ' c#D\n'] Now I
I have taken following array; to fill-up gallery: private Integer[] mImageIds = { R.drawable.one,
I have the following array: Array ( [0] => BCD [1] => ACE [2]
I have the following array: a = magic(12); a = a(:,1); It's a list
I have the following array in fortran77 dec(3, 25000), even if only the 8898
Say I have a class, something like the following; class MyClass { public: MyClass();
i want to implement the following exhaustive match, but i can't figure out to

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.