Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iLoveDeveloping

Suspended
Original poster
Sep 24, 2009
596
2,366
Ireland
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?
 
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"
 
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"

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.
 
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 :)
 
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 :)
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.
 
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?
 
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().
 
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().
Ah see that clears it up for me, I didnt know NSLog was actually NSLog().
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.