Email App Message?

Discussion in 'iOS Programming' started by iLoveDeveloping, Feb 3, 2010.

  1. iLoveDeveloping macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #1
    Hey,

    Im sending a message in my app by email, but i cant get the spacing to work in the code!

    I have :

    Code:
    NSString *emailBody = @"Your Message In Here!";
    But if i write the message like this:

    Code:
    NSString *emailBody = @"Your Message In Here!
    
    Signed Blah Blah";
    It doesn't work and i get a whole load of errors! How do i format my email text in the code, so i can make it look like a real formatted email?
     
  2. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #2
    Just use escape chars. \n is the char for new line break. use two of those so your string would look like.
    Code:
    NSString *emailBody = @"Your Message In Here!\n\nSigned Blah Blah"
     
  3. iLoveDeveloping thread starter macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #3
    Cool thanks! :apple:
     
  4. RobertD63 macrumors 6502

    Joined:
    Feb 17, 2008
    Location:
    A place
    #4
    Just wondering here. Wouldn't it be better practice to enclose it on parentheses?
    Code:
    NSString *emailBody = @("Your Message In Here!\n\nSigned Blah Blah")
    Just wondering out loud here.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    No, not really. In fact, that will give you a compile error. Don't do it.

    I'm curious why you would think that better though. Care to elaborate?
     
  6. RobertD63 macrumors 6502

    Joined:
    Feb 17, 2008
    Location:
    A place
    #6
    Just cause when ever I was messing around with anything that displays text (NSLog) I wrote it as this:
    Code:
    NSLog(@"text here");
    Just wondering if it carried over yet. Guess not, thanks for the clarification :)
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    The difference is that with NSLog you're putting the string @"..." inside the parentheses.
    Code:
    NSLog(@"text");
    The way you had it, the parentheses were inside the @, which the compiler will choke on. And the reason for the parentheses with NSLog is that NSLog is a C-style method call and not an Objective-C method call.
     
  8. RobertD63 macrumors 6502

    Joined:
    Feb 17, 2008
    Location:
    A place
    #8
    Oh duh, excuse me, I'm a learning programmer here (I dont have my training wheels yet, just learning to walk so to speak). So would it still give a complier error if I had typed it right? Or is that specific to NSLog?
     
  9. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #9
    I don't see why surrounding an NSString with parenthesis wouldn't work, its just kind of pointless. Think about it like a math problem. 1+1 is no different than (1+1). Its very different from the quotes in NSLog() because NSLog() is a method. Its good that you're curious and asking questions though. So if you're trying to do something like this:
    Code:
    (@"%i",integer);
    It won't work because its different from NSLog().
     
  10. RobertD63 macrumors 6502

    Joined:
    Feb 17, 2008
    Location:
    A place
    #10
    Ah see that clears it up for me, I didnt know NSLog was actually NSLog().
     

Share This Page