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

  • Home
  • SEARCH
  • 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 6995663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:03:30+00:00 2026-05-27T20:03:30+00:00

i have a string declare as such NSString *str = [[NSString alloc] initWithFormat:@I require

  • 0

i have a string declare as such

NSString *str = [[NSString alloc] initWithFormat:@"I require an average GPA of at least %.2f to achieve my Goal of %@ this semester - NTU GPA Calculator", pgagoal,(NSString *)[myPickerDelegate.myGoal objectAtIndex: [myPicker selectedRowInComponent:0]]];

i declared a global variable

NSStrinng *tweetString

and wants to copy the the string in str to tweetString. how should i copy it? since both are pointers, i tried:

tweetString = str;

or

tweetString = [NSString stringWithFormat:@"%@", str];

but it doest work.


EDIT:
my code:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex1{
NSLog(@"buttonindex 1 clicked");

NSString *str2;
NSLog(@"tweetString before if: %@", tweetString);
if (pgagoal < 0) {
    NSString *str2 = [[NSString alloc] initWithFormat:@"Confirm, Guarantee, Chop and Stamp! I can achieve my Goal of %@ this semester - NTU GPA Calculator", (NSString *)[myPickerDelegate.myGoal objectAtIndex: [myPicker selectedRowInComponent:0]]];
    NSLog(@"tweetString: < 0 %@", str2);
}
else if (pgagoal > 5){
    NSString *str2 = [[NSString alloc] initWithFormat:@"Its impossible!, i need an average GPA of at least %.2f to achieve %@ this semester - NTU GPA Calculator", pgagoal,(NSString *)[myPickerDelegate.myGoal objectAtIndex: [myPicker selectedRowInComponent:0]]]; 
    NSLog(@"tweetString: >5 %@", str2);
}

else{
    NSString *str2 = [[NSString alloc] initWithFormat:@"I require an average GPA of at least %.2f to achieve my Goal of %@ this semester - NTU GPA Calculator", pgagoal,(NSString *)[myPickerDelegate.myGoal objectAtIndex: [myPicker selectedRowInComponent:0]]];
    NSLog(@"tweetString with else: %@", str2);
}

//did i update tweetString correctly?
tweetString = [NSString stringWithString:str2]; <-- stop working from this point EXC_BAD_ACCESS

NSLog(@"tweetString after if else: %@", tweetString);
[self sendEasyTweet:tweetString];
NSLog(@"tweetString: %@", tweetString);
[str2 release];
}

- (void)sendEasyTweet {    
// Set up the built-in twitter composition view controller.
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];


// Set the initial tweet text. See the framework for additional properties that can be set.
[tweetViewController setInitialText:tweetString];

// Create the completion handler block.
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {        
    switch (result) {
        case TWTweetComposeViewControllerResultCancelled:
            // The cancel button was tapped.
            NSLog(@"Tweet cancelled");
            break;
        case TWTweetComposeViewControllerResultDone:
            // The tweet was sent.
            NSLog(@"Tweet done");
            break;
        default:
            break;
    }

    // Dismiss the tweet composition view controller.
    [self dismissModalViewControllerAnimated:YES];
}];

// Present the tweet composition view controller modally.
[self presentModalViewController:tweetViewController animated:YES];
}

EDIT2:
Debbuger output:

2011-12-29 09:54:22.963 GPA[487:707] buttonindex 1 clicked
2011-12-29 09:54:22.966 GPA[487:707] tweetString before if: NTU GPA Calculator <-- i init the string at viewDidLoad
2011-12-29 09:54:22.968 GPA[487:707] tweetString with else: I require an average GPA of at least 1.56 to achieve my Goal of Third Class Honors this semester - NTU GPA Calculator
(gdb)

EDIT3:
my tweetString is declared in view controller.h as

    @interface GPAMainViewController : UIViewController <GPAFlipsideViewControllerDelegate>{
UIPickerView * myPicker;
GPAAppDelegate * myPickerDelegate;
IBOutlet UITextField *txtGPA;
IBOutlet UITextField *txtTotalAU;
IBOutlet UITextField *txtRemainingAU;
double pgagoal;
NSString *tweetString;
}

@property (nonatomic, retain) IBOutlet UIPickerView * myPicker;
@property (nonatomic, retain) IBOutlet GPAAppDelegate *myPickerDelegate;
@property (nonatomic, retain) UITextField *txtGPA;
@property (nonatomic, retain) UITextField *txtTotalAU;
@property (nonatomic, retain) UITextField *txtRemainingAU;
@property (nonatomic, retain) NSString *tweetString;

-(IBAction)finishEditing:(id)sender;
-(IBAction)calculateGoal: (id) sender;
-(IBAction)showInfo:(id)sender;
-(IBAction)nextField:(id)sender;
-(IBAction)resetField:(id)sender;
-(void)sendEasyTweet:(id)sender;
  • 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-27T20:03:31+00:00Added an answer on May 27, 2026 at 8:03 pm

    The reason that it doesn’t work (it is probably crashing with an EXC_BAD_ACCESS) is because the scope of the variable str is only within the block in which it is declared, the block of the else part of your if/else statement. Try something like this:

    -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex1 {
        NSString* str; //declare string here so it is in scope the entire method
        .
        . //your code
        .
        .
    
        if(yourConditionHere) {
            //make sure you initialize str here as well so if the else part of the statement
            // isn't executed, you aren't trying to access an uninitialized variable
        } else {
            str = [[NSString alloc] initWithFormat:@"I require an average GPA of at
                least %.2f to achieve my Goal of %@ this semester - NTU GPA Calculator", 
                pgagoal,(NSString *)[myPickerDelegate.myGoal objectAtIndex: [myPicker 
                selectedRowInComponent:0]]]; //give str a value
    
            NSLog(@"tweetString with else: %@", str);
        } //Variable str is going out of scope here the way you have your code set up now
    
        tweetString = [str copy];
    
        NSLog(@"tweetString after if else: %@", tweetString);
        [self sendEasyTweet:tweetString];
        NSLog(@"tweetString: %@", tweetString);
        [str release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I have a hardcoded string I declare like this name = uPar Catégorie
I have string like this /c SomeText\MoreText Some Text\More Text\Lol SomeText I want to
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have: String uri = @drawable/myresource.png; How can I load that in ImageView? this.setImageDrawable?
If I have a function declared as such: public static void main(String[] args){ blahblahlbah;
I have a map declared as follows: map < string , list < string
I have two domains declared in my app. class Posts { String title String
I have string that I want to chop to array of substrings of given
I have string like \LESSING\root\cimv2:Win32_UserAccount.Domain=LESSING,Name=Admin How to convert it to LESSING\Admin using Framework?

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.