Unexpected @ in program

Discussion in 'iOS Programming' started by emeryccc, Oct 23, 2012.

  1. emeryccc macrumors newbie

    Joined:
    Oct 23, 2012
    #1
    I am trying to post some login data but the NSStrings lines are not working... Anyone know why?


    For example, these lines work
    Code:
    NSString *wallPost = @"the super wall post";
            
            NSString *post = [NSString = @”username=%@&password=%@”,usernameField.text, passwordField.text;
                           
      
    But these don't

    Code:
          NSString *hostStr = @”THIS IS MY URL/iphonelogin-do.php?”;
    Code:
    
    #import "LoginTableViewController.h"
    
    @interface LoginTableViewController ()
    @property (weak, nonatomic) IBOutlet UITextField *UIEmailTextField;
    @property (weak, nonatomic) IBOutlet UITextField *UIPasswordTextField;
    
    @end
    
    @implementation LoginTableViewController
    @synthesize UIEmailTextField;
    @synthesize UIPasswordTextField;
    
    - (id)initWithStyle:(UITableViewStyle)style
    {
        self = [super initWithStyle:style];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    }
    
    - (void)viewDidUnload
    {
        [self setUIEmailTextField:nil];
        [self setUIPasswordTextField:nil];
        [super viewDidUnload];
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
    #pragma mark - barButton Outlet
    
    - (IBAction)loginButtonPressed:(UIBarButtonItem *)sender {
        {
            
            NSString *wallPost = @"the super wall post";
            
            NSString *post = [NSString = @”username=%@&password=%@”,usernameField.text, passwordField.text;
                           
            NSString *hostStr = @”THIS IS MY URL/iphonelogin-do.php?”;
            hostStr = [hostStr stringByAppendingString:post];
            NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
            NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
            
            
            
            
            
            
            
            if([serverOutput isEqualToString:@”Yes”]){
                
                
                UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@”Congrats” message:@”You are authorized “
                                                                      delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil, nil];
                
                [alertsuccess show];
                [alertsuccess release];
                
                
            } else {
                UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@”Error” message:@”Username or Password Incorrect”
                                                                      delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil, nil];
                [alertsuccess show];
                [alertsuccess release];
                
            }
            
        }
    
    }
    
    @end
    
    Also, it says this isn't allowed :(


    Code:
    [alertsuccess release];
    Thanks,
    Emery
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Don't work how? Please elaborate.

    Are you using ARC?
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    The first line seems fine to me, but I find it difficult to believe the second line works.

    First, it's not even valid syntax. You aren't allowed to assign a string literal to a class-name. It's just nonsense as given, and I can't even figure out what it's intended to be. If you copied it from somewhere, please post the URL or whatever source you copied it from. Be specific.

    Second, you don't have a valid double-quote character in the second line. Somehow you have a "smart quote", which is to say, a typographer's quote, or a curly quote. Here's a valid (neutral) double-quote character, in a big font:
    Code:
    [SIZE="5"]test = @[COLOR="Red"]"[/COLOR]example";
    [/SIZE]
    Here's yours, in a big font:
    Code:
    [SIZE="5"]NSString = @[COLOR="red"]”[/COLOR]username=%@&pas[/SIZE]
    I've hilited each character in red. The neutral quote is the only form that Objective-C recognizes.

    Curly quotes often occur when blindly copying and pasting from web pages that contain curly quotes, or copying and pasting text from a word-processer that automatically replaces neutral quote-marks with curly quotes. There are other possible causes, but those two are pretty common.

    The second line isn't the only use of curly quotes; you have more. Find them by selecting the curly quote, pressing command-E to Use the Selection for Find, then command-G to Find Next.

    http://en.wikipedia.org/wiki/Quotation_mark
     
  4. emeryccc thread starter macrumors newbie

    Joined:
    Oct 23, 2012
    #4
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    Tumblr has cleverly changed every neutral quote to a curly quote.


    This is what I see for the username and password line. It seems correct, except for the curly quotes:
    Code:
    NSString *post =[NSString stringWithFormat:@”username=%@&password=%@”,usernameField.text, passwordField.text];
    
    I have no idea how you ended up with this:
    Code:
    NSString *post = [NSString = @”username=%@&password=%@”,usernameField.text, passwordField.text;
    

    There is a link to source files at the bottom of that tumblr post (find "Source is now available"). You could try that instead of copy-pasting from the curly-quoted text.
     
  6. emeryccc thread starter macrumors newbie

    Joined:
    Oct 23, 2012
    #6
    Thank you!!!

    That worked, i just had to replace the quotes and it worked! But, now when i run the app, the NSString *post line crashes it, it say Thread1:Breakpoint1 with that line in green, here is the code now

    Code:
    //
    
    #import "LoginTableViewController.h"
    
    @interface LoginTableViewController ()
    @property (weak, nonatomic) IBOutlet UITextField *UIEmailTextField;
    @property (weak, nonatomic) IBOutlet UITextField *UIPasswordTextField;
    
    @end
    
    @implementation LoginTableViewController
    @synthesize UIEmailTextField;
    @synthesize UIPasswordTextField;
    
    - (id)initWithStyle:(UITableViewStyle)style
    {
        self = [super initWithStyle:style];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    }
    
    - (void)viewDidUnload
    {
        [self setUIEmailTextField:nil];
        [self setUIPasswordTextField:nil];
        [super viewDidUnload];
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
    #pragma mark - barButton Outlet
    
    - (IBAction)loginButtonPressed:(UIBarButtonItem *)sender {
        {
            
         
            NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",UIEmailTextField.text, UIPasswordTextField.text];
                           
            NSString *hostStr = @"http://midislandsnoblazers.ca/iphonelogin-do.php?";
            hostStr = [hostStr stringByAppendingString:post];
            NSData *dataURL =  [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
            NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
            
            
            
            
            
            
            
            if([serverOutput isEqualToString:@"Yes"]){
                
                
                UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Congrats" message:@"You are authorized"
                                                                      delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                
                [alertsuccess show];
              //  [alertsuccess release];
                
                
            } else {
                UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Username or Password Incorrect"
                                                                      delegate:self cancelButtonTitle:@"OK"otherButtonTitles:nil, nil];
                [alertsuccess show];
             //   [alertsuccess release]; Commented out because it doesn't allow this line ...
                
            }
            
        }
    
    }
    
    @end
    
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Does it give you an error message?
     
  8. emeryccc thread starter macrumors newbie

    Joined:
    Oct 23, 2012
    #8
    :/

    Not really, i just get the thread1 breakpoint thing all in green those lines
     

Share This Page