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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:07:53+00:00 2026-05-13T19:07:53+00:00

I’ve got a problem with a NSString in my app. I’ve defined it in

  • 0

I’ve got a problem with a NSString in my app.
I’ve defined it in the header file of my view controller.

    NSString *locationCoordinates;

and I set its value in a -(void) method.

- (void)locationUpdate:(CLLocation *)location {
    <...>

    NSArray *locArray = [locString componentsSeparatedByString:@", "];

    NSString *xCoordinate = [locArray objectAtIndex:0];
    NSString *yCoordinate = [locArray objectAtIndex:1]; 

    locationCoordinates = [NSString stringWithFormat:@"%@,%@", xCoordinate, yCoordinate];
}

In this method, I can print it to the console with

NSLog(locationCoordinates);

But if I want to view it in the console in another method, my app instantly quits.

- (IBAction)saveAndReturnToRootView {
    NSLog(locationCoordinates);
}

The console tells me:

2010-02-24 14:45:05.399 MyApp[73365:207] *** -[NSCFSet length]: unrecognized selector sent to instance 0x4c36490
2010-02-24 14:45:05.400 MyApp[73365:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFSet length]: unrecognized selector sent to instance 0x4c36490'
2010-02-24 14:45:05.401 MyApp[73365:207] Stack: (
  32887899,
  2434934025,
  33269819,
  32839286,
  32691906,
  32417461,
  32527181,
  32527085,
  32747749,
  356942,
  630491,
  63461,
  2868313,
  4782069,
  2868313,
  3275682,
  3284419,
  3279631,
  2973235,
  2881564,
  2908341,
  40984273,
  32672640,
  32668744,
  40978317,
  40978514,
  2912259,
  9744,
  9598
)

How can I solve this problem?

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-13T19:07:54+00:00Added an answer on May 13, 2026 at 7:07 pm

    You arent retaining the String, so the memory is being cleared up. This causes the crash when you try to access it.

    To retain it, you can add the following line

    [locationCoordinates retain];
    

    Remember to release it when you no longer need it – probably in the destructor of your class, or else you will have a memory leak.


    It is standard practice in Objective C to use properties for such class members. In the header file use

    @property (nonatomic, retain) NSString *locationCoordinates;
    

    Then in the implementation chuck in a

    @synthesize locationCoordinates;
    

    When you access locationCoordinates access it through self as :

    self.locationCoordinates = [NSString stringWithFormat:@"%@,%@", xCoordinate, yCoordinate];
    

    Objective C will create a getter and setter property that will handle the retain for you in the most efficient manner.

    Incidentally, the nonatomic keyword in the property tells objective c that you dont need it to create any thread synchronization around the property access. If you are going to be multithreading the class, you should consider removing nonatomic. This will then ensure the property access is thread safe.

    No point doing any work that you can get the compiler to do for you!

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

Sidebar

Ask A Question

Stats

  • Questions 388k
  • Answers 388k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Operator precedence is fixed in the Scala Reference - 6.12.3… May 15, 2026 at 12:32 am
  • Editorial Team
    Editorial Team added an answer The warning is because you are violating the strict aliasing… May 15, 2026 at 12:32 am
  • Editorial Team
    Editorial Team added an answer Javascript treats single and double quotes as string delimiters. If… May 15, 2026 at 12:32 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.