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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:02:39+00:00 2026-06-06T10:02:39+00:00

This is my first time using this site and I am quite new to

  • 0

This is my first time using this site and I am quite new to Objective-c. I’m sure this is a simple question but for some reason I am having a lot of issues. The app is designed to have the user enter a string via textfield, then it will pick the rest of the sentence and display it. The issue appears to be that my *name will be retained after the keyboard method and work once in the changelabel method. Then if i press the button again, invoking the changelabel method, the name appears to have been released and crashes the app.
#import
#import “Array.h”

@interface RandomBoredViewController : UIViewController {
UILabel *label;
UIButton *button;
UITextField *textField;
Array *array;
NSString *name;
NSString *description;
NSMutableString *whole;
}
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, retain) IBOutlet UIButton *button;
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) Array *array;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *description;
@property (nonatomic, retain) NSMutableString *whole;

-(IBAction) keyBoard;
-(IBAction) changeLabel;

@end

and my .m

#import "RandomBoredViewController.h"

@implementation RandomBoredViewController

@synthesize label;
@synthesize checker;
@synthesize button;
@synthesize textField;
@synthesize array;
@synthesize name;
@synthesize description;
@synthesize whole;


-(IBAction) changeLabel {
NSLog(@"Button being pushed");
description = [array getString];
NSLog(@"%@",description);
NSLog(@"%@",name);
name = [NSString stringWithString:name];
whole = [NSMutableString stringWithString:name];
NSLog(@"%@",name);
NSLog(@"%@",whole);
[whole appendString:description];
NSLog(@"%@",name);
NSLog(@"%@",whole);
label.text = whole;
NSLog(@"%@",name);
}

-(IBAction) keyBoard {
name = [NSString stringWithString:textField.text];
NSLog(@"%@",name);
label.text = [NSString stringWithString: name];
[textField resignFirstResponder];
}

- (void)viewDidLoad {
[super viewDidLoad];
array = [[Array alloc]init];
[array createArray];
NSLog(@"%i",[array arrayCount]);
whole = [[NSMutableString alloc]init];
name = [[NSString alloc]init];
}

- (void)dealloc {
[super dealloc];
[label release];
[button release];
[textField release];
[array release];
//[name release];
[description release];
}

@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-06T10:02:43+00:00Added an answer on June 6, 2026 at 10:02 am

    Taking one thing in microcosm, the code you’ve posted creates two things named name — an instance variable and a property.

    Instance variables are directly accessed storage. They have no behaviour.

    Properties are named attributes accessed via getters and setters. So they may have arbitrary behaviour. They may report the values of instance variables or values calculated from instance variables or values calculated or obtained by any other means. Relevantly, the setters may retain, assign or act in any other way.

    Instance variables may be accessed only by the instance of a class they belong to. Properties are usually intended to be accessed by anyone.

    Since retaining is a behaviour and you’ve ascribed it to your name property, setting something to it would result in a retain. Instance variables can’t have behaviour, so setting a value to it doesn’t result in a retain or anything else.

    As a result, this line:

    name = [NSString stringWithString:name];
    

    Creates a new string and returns a non-owning reference. Which means it’ll definitely last for the duration of this autorelease pool (ie, you explicitly may pass it as an argument or return it safely, assuming you haven’t taken manual control of your autorelease pools).

    You store that reference to your instance variable. Instance variables don’t have behaviour so the reference is stored but you still don’t own that object. It’s still only safe to use for the duration of that autorelease pool.

    So when you access it in that method it’s safe. When you access it later it’s unsafe.

    If instead you’d gone with:

    self.name = [NSString stringWithString:name];
    

    Then you’d have set that string to be the new value of the property. Because your property has the retain behaviour, you’d subsequently have completely safe access to the string object, until you say otherwise.

    Because you’ve got a property with exactly the same name as an instance variable, you could subsequently access it either as just name or as self.name. Similarly you could have stored directly to the instance variable rather than via the property if you’d ensured you had an owning reference manually.

    As suggested above, use of ARC is a way to get the compiler to figure all this stuff out for you.

    That issue is what causes your code to crash — you end up trying to access a reference that has ceased to be valid. If you’d taken ownership of it then it would have continued to exist at least as long as you kept ownership.

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

Sidebar

Related Questions

So this is my first time using cookies and i'm having some trouble setting
this is my first time really using this site. I'm relatively new to using
This is my first time using lightbox which uses jquery framework. But when I
I'm fairly new to both Django and Python. This is my first time using
This is my first post, but I've loved using this site as resource for
This is my first time using this site so sorry for any bad formatting
This is my first time using Magento. I upgraded this site from 1.4.1.1 to
I am recoding my site using CodeIgniter. This is my first time using an
I'm certain this is a dumb newbie question, but this is the first time
I am doing this first time so I need some help. I am using

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.