Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to update a string variable with another string variable
    primarykey
    data
    text
    <p>i have a string declare as such</p> <pre><code>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]]]; </code></pre> <p>i declared a global variable</p> <pre><code>NSStrinng *tweetString </code></pre> <p>and wants to copy the the string in str to tweetString. how should i copy it? since both are pointers, i tried:</p> <pre><code>tweetString = str; </code></pre> <p>or</p> <pre><code>tweetString = [NSString stringWithFormat:@"%@", str]; </code></pre> <p>but it doest work.</p> <hr> <p>EDIT: my code:</p> <pre><code>-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex1{ NSLog(@"buttonindex 1 clicked"); NSString *str2; NSLog(@"tweetString before if: %@", tweetString); if (pgagoal &lt; 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: &lt; 0 %@", str2); } else if (pgagoal &gt; 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: &gt;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]; &lt;-- 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]; } </code></pre> <p>EDIT2: Debbuger output:</p> <pre><code>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 &lt;-- 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) </code></pre> <p>EDIT3: my tweetString is declared in view controller.h as</p> <pre><code> @interface GPAMainViewController : UIViewController &lt;GPAFlipsideViewControllerDelegate&gt;{ 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; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload