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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:12:05+00:00 2026-05-28T22:12:05+00:00

Static variables are variables allocated statically at compile time. My doubt is for what

  • 0

Static variables are variables allocated statically at compile time. My doubt is for what purpose some variables are declared statically? I didn’t have used any static variable in my code till now. From the apple code http://developer.apple.com/library/ios/#samplecode/CryptoExercise/Introduction/Intro.html
in securityWrapper.m, there is a line

static SecKeyWrapper * __sharedKeyWrapper = nil; 

what is the use of statically allocating __sharedKeyWrapper here?

I have seen the use of static key word in so many codes. So kindly explain the use and benefits when static keyword.

Thanks in advance.

  • 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-28T22:12:05+00:00Added an answer on May 28, 2026 at 10:12 pm

    That file global is a singleton, used for sharing an instance of a class.

    The reason it’s static in Objective-C is internal linkage. In practice, this means the variable can not be seen outside the file it is declared in. If another file declares a variable with the same name, they’re two different variables.

    Keep in mind that the way Objective-C instances work, the instance won’t actually be allocated automatically. Rather, you have a pointer to the instance. The code will still have to do something like:

    if ( !_sharedKeyWrapper ) {
        _sharedKeyWrapper = [[SecKeyWraper alloc] initBlahBlah];
    }
    

    See links for more.

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

Sidebar

Related Questions

When static variable is allocated i.e. when you declare class or at the time
I remember reading that static variables declared inside methods is not thread-safe. (See What
I've read that static variables are used inside function when one doesn't want the
I have global static variables in a C library, which generate exceptions in a
How are static variable treated by the garbage collector and where are they allocated
I need a dynamically allocated bi-dimensional array of objects. I declared a static pointer
Say I have defined a variable like this (C++): static const char str[] =
I'm quite confident that globally declared variables get allocated (and initialized, if applicable) at
A static variable is allocated for the entire duration of a program's execution, so
If I have two static variables in different compilation units, then their initialization order

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.