Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-04-2010, 05:44 PM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 10
Italianblend is on a distinguished road
Default very basic \n question

Hi, I am very new to programming, currently in chapter1 of Programming in ObjectiveC 2.0. Basic question about using \n to make a new line in a NSLog...function thingy

I understand that\n is a convenient way to avoid writing NSLog (@" all the time and it just starts a new line for you. But if you use \n your lines will stretch out farther than your screen. Is there a way to keep one NSLog string using\n but have it broken up on your screen just to keep track of the code better?

Like, I tried

(@ "This is line one.\nThis is line two\n
This is line three");

But this showed errors. I'm just trying to use several \n without having to scroll across the screen to see the entire code.

I hope I'm making sense. Thanks =)
Italianblend is offline   Reply With Quote
Old 06-04-2010, 09:54 PM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 107
JDave is on a distinguished road
Default Looks right????

Quote:

(@ "This is line one.\nThis is line two\n
This is line three");

But this showed errors. I'm just trying to use several \n without having to scroll across the screen to see the entire code.

I hope I'm making sense. Thanks =)
Looks like you have it correct... but what happened to NSLog???

You are doing this, right??? :

Code:
NSLog(@"This is line one.\nThis is line two\nThis is line three");
JDave is offline   Reply With Quote
Old 06-04-2010, 10:44 PM   #3 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

I think you're asking how to make one string out of multiple lines of code. You can use it in combination with the \n character, but they're not related.

You can create a multi-line string by closing your quotes, and then opening them again on the next line. Like this:

Code:
NSLog(@"This is"

"one really" 

"long \n string with one" 


"break in the middle.", nil);
That will appear like so:

Code:
This isone reallylong 
 string with onebreak in the middle.
No other punctuation like + or . is requires. Adjacent strings are treated as one string.

Code:
NSLog(@"This \
should \
work \
too." , nil);
__________________

Free Games!

Last edited by smasher; 06-05-2010 at 10:09 AM.
smasher is offline   Reply With Quote
Old 06-05-2010, 06:18 AM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 10
Italianblend is on a distinguished road
Default

NSLog @( "Thank You"

"very much for explaining"

"this to me =)" );
Italianblend is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 468
14 members and 454 guests
7twenty7, AlanFloyd, David-T, imac74, Jaxen66, logan, lovoyl, Music Man, mutantskin, Sami Gh, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:09 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0