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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:17:27+00:00 2026-05-20T19:17:27+00:00

I would like to define the following function in Objective-C. I have provided pseudo-code

  • 0

I would like to define the following function in Objective-C. I have provided pseudo-code to help illustrate what I’m trying to do.

PSEUDOCODE:

function Foo(param) {
  string temp; 

if(param == 1) then
  temp = "x";
else if(param == 2) then
  temp = "y";
else if(param == 3) then 
  temp = "z";
else
  temp = "default";
end if    

  return temp;
}

For some reason if I do this… the variable who I assign it to results in a “BAD Access” error.

I don’t know what the difference between:

static NSstring *xx;

or the non-static:

NSString *xx;

declarations are, and how or why I would want to use one over the other.

I also do not fully understand the initializers of NSString, and how they differ. For example:

[[NSString alloc] initWithString:@"etc etc" ];

or the simple assignment:

var = @""

or even:

var = [NSString stringWithString:@"etc etc"];

Can you give me a hand please?

So far, using the NSString value returned from functions like those listed above, always causes an error.

  • 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-20T19:17:28+00:00Added an answer on May 20, 2026 at 7:17 pm
    static NSstring *xx;
    

    That declares a statically allocated variable, much like it does in C.

    NSstring *xx;
    

    Inside a method that declares a normal local stack variable, just as it does in C.

    As you should be aware, the difference between the two is that the first will keep its value between invocations of the function (and can cause trouble if the function is called from multiple threads).

    [[NSString alloc] initWithString:@"etc etc"]
    

    That creates a new NSString object, with the contents etc etc. This may or may not be the same as any other NSString object in your program with the same contents, but you don’t have to care. Memory management wise, you own it, so you are responsible for ensuring that you eventually call release or autorelease on it to avoid leaking memory.

    @"etc etc"
    [NSString stringWithString:@"etc etc"]
    

    Those are basically the same. Both give you an NSString object with the contents etc etc. This may or may not be the same as any other NSString object in your program with the same contents, but you don’t have to care. Memory management wise, you do not own it, so you must not call release or autorelease on the object unless you first took ownership by calling retain. Also, since you do not own it, you can use it within your method, pass it as a parameter to other methods, and even use it as the return value from your method, but you may not store it in an ivar or static variable without taking ownership by calling retain or making a copy (with copy).

    Also, note that "" and @"" are very different. The first gives you a const char * exactly as it does in C, while the second gives you an NSString object. Your program will crash if you use a const char * where the code expects an NSString object.

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

Sidebar

Related Questions

I have some debugging code that looks like the following: #define STRINGIFY(x) #x #define
I have Foo.hpp and Foo.cpp, i'd like to define a virtual function virtual void
I would like to know how to define a returntype in a function in
I have got the following issue, my function appends code to a string $string
I would like to be able to define and use a custom type in
Is there a way to define the weekly period I would like to use
We would like to have user defined formulas in our c++ program. e.g. The
I would like to write this as a user defined function: private double Score(Story
I have an actionscript file that defines a class that I would like to
I have defined a personalizable property on a web part and I would like

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.