Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional iPhone and iPad Database Application Programming
This is the forum to discuss the Wrox book Professional iPhone and iPad Database Application Programming by Patrick Alessi; ISBN: 978-0-470-63617-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional iPhone and iPad Database Application Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 7th, 2011, 09:18 PM
Authorized User
 
Join Date: May 2011
Posts: 19
Thanks: 9
Thanked 0 Times in 0 Posts
Default Chapter 1 - Help!

Went through example in chapter 1 fine. However, on pg. 17, book says you can modify DataModel to use a text file as a datasource. On page 18 there is code for reading a text file. However, the book does not explain how to change the previous code in order to actually get this to work. Does anyone know where to input the code on page 18? (e.g. what file?, what location in the file?, also - shouldn't this replace other code-e.g. myData = [[NSArray alloc] initWithObjects:@"Albert", @"Bill"...?) Thanks in advance for any help!
  #2 (permalink)  
Old May 8th, 2011, 08:05 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

You are replacing the initialization code in the DataModel.m file. This is a way to do it. Comment out or remove the existing allocation and assignment to myData and assign to myData the contents of the textfile.

Code:
-(id)init
{
    if (self = [super init])
    {
     /*   // Initialization code
        myData = [[NSArray alloc] initWithObjects:@"Albert", @"Bill", @"Chuck", 
                  @"Dave", @"Ethan",@"Franny", @"George", @"Holly", @"Inez", 
                  nil];
	  */
		NSError *error;
		NSString *textFileContents = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] 
																		 pathForResource:@"myTextFile" ofType:@"txt"]
															   encoding:NSUTF8StringEncoding
																  error:&error];
		if (textFileContents == nil) {
			NSLog(@"Error reading text file. %@", [error localizedFailureReason]);
		}
		
		myData = [textFileContents componentsSeparatedByString:@"\n"];
	
    }
    return self;
}
This assumes that you have created the .txt file (Create it in TextEdit e.g., and save as plain text not .rtf) and added (copied the file) to the project.

Bob
The Following User Says Thank You to thepianoguy For This Useful Post:
tecky10 (May 9th, 2011)
  #3 (permalink)  
Old May 9th, 2011, 03:06 AM
Authorized User
 
Join Date: May 2011
Posts: 19
Thanks: 9
Thanked 0 Times in 0 Posts
Default Thanks a million!

Yea, it worked! Thanks so much for the clear instructions along with the code. I really appreciate it! :-)
  #4 (permalink)  
Old May 16th, 2011, 01:43 PM
Authorized User
Points: 60, Level: 1
Points: 60, Level: 1 Points: 60, Level: 1 Points: 60, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default Where did you put the file?

My project compiles without error but there is no output, the lines are blank! I need to know where do you put the myTextFile.txt file? It is not clear in the instructions where to put this file. I'm not sure Xcode is reading the file
  #5 (permalink)  
Old May 16th, 2011, 01:59 PM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

You should add the .txt file to the project. There are 3 ways to do this:

1.Drag and drop it into the Project Navigator (Xcode 4) or the Groups & Files Pane (Xcode 3.x).
2. Choose File>Add Files to… (Xcode 4) or Project>Add to Project (Xcode 3.x), navigate to your file and select it.
3. Step 2 is also available as a context menu in the Project Navigator (Xcode 4) and the Groups & Files pane (Xcode 3.x)

In all cases a dialog sheet will present. Make sure the Copy file(s) into the destination… is checked, and Click Add

Hope this makes sense.

Bob
  #6 (permalink)  
Old May 16th, 2011, 02:38 PM
Authorized User
 
Join Date: May 2011
Posts: 19
Thanks: 9
Thanked 0 Times in 0 Posts
Default File location for .txt file

<<My project compiles without error but there is no output, the lines are blank! I need to know where do you put the myTextFile.txt file? It is not clear in the instructions where to put this file. I'm not sure Xcode is reading the file>>

I just put the .txt file in the main 'groups & files' location. It works there, although I suspect it should really be in the 'resources' folder. But, like I said, it did work there. You can tell that Xcode is reading the file if you try 'build and run'. If it reads the file, you'll see your text from the .txt file appear in the simulator.

Hope that helps.

Best wishes.
  #7 (permalink)  
Old May 16th, 2011, 04:13 PM
Authorized User
Points: 60, Level: 1
Points: 60, Level: 1 Points: 60, Level: 1 Points: 60, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks! it Worked!!!!
  #8 (permalink)  
Old May 16th, 2011, 10:49 PM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

Quote:
I just put the .txt file in the main 'groups & files' location. It works there, although I suspect it should really be in the 'resources' folder
.

The groups in the Groups & Files Pane are purely organizational and have no impact on how the program compiles. The folders (groups) are present in the Xcode interface but not in the actual project directory. So files can actually be arranged anyway you wish in the Groups & Files Pane. (Obviously, it is a good idea to set up a structure that makes sense for a more efficient workspace)

Bob
The Following User Says Thank You to thepianoguy For This Useful Post:
tecky10 (May 17th, 2011)
  #9 (permalink)  
Old May 17th, 2011, 12:34 AM
Authorized User
 
Join Date: May 2011
Posts: 19
Thanks: 9
Thanked 0 Times in 0 Posts
Default Thanks for info.

<<The groups in the Groups & Files Pane are purely organizational and have no impact on how the program compiles. The folders (groups) are present in the Xcode interface but not in the actual project directory. So files can actually be arranged anyway you wish in the Groups & Files Pane. (Obviously, it is a good idea to set up a structure that makes sense for a more efficient workspace)>>

Thanks for this info. This is good to know!
  #10 (permalink)  
Old January 31st, 2012, 04:42 PM
Registered User
Points: 31, Level: 1
Points: 31, Level: 1 Points: 31, Level: 1 Points: 31, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Talking thanks

This worked for me too - thanks.
 


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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 - Code Download Missing for this Chapter dbaechtel BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 0 August 11th, 2009 11:02 AM
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM
Generics chapter 12 difficult chapter i found ...? Larryz C# 2005 1 July 4th, 2007 09:40 PM



All times are GMT -4. The time now is 12:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.