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 09-29-2009, 04:35 AM   #1 (permalink)
ranjeet_bhatta
 
Join Date: Sep 2009
Posts: 16
afixi.ranjeet is on a distinguished road
Default NSFileManager

I can't understand the purpose of the following code:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
self.pathToUserCopyOfPlist = [documentsDirectory stringByAppendingPathComponent:@"appData.plist"];

Can someone help me to understand the above?
afixi.ranjeet is offline   Reply With Quote
Old 09-29-2009, 05:46 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 5
stroodle is on a distinguished road
Default

Quote:
Originally Posted by afixi.ranjeet View Post
I can't understand the purpose of the following code:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
self.pathToUserCopyOfPlist = [documentsDirectory stringByAppendingPathComponent:@"appData.plist"];

Can someone help me to understand the above?
its just asigning a whole bunch of stuff it doesn't actually do anything yet
i think at least (im still new to this).
stroodle is offline   Reply With Quote
Old 10-01-2009, 12:04 PM   #3 (permalink)
Registered Member
 
fxshot's Avatar
 
Join Date: Feb 2009
Location: Stevenson Ranch, California
Posts: 75
fxshot is on a distinguished road
Default

Quote:
Originally Posted by afixi.ranjeet View Post
I can't understand the purpose of the following code:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
self.pathToUserCopyOfPlist = [documentsDirectory stringByAppendingPathComponent:@"appData.plist"];

Can someone help me to understand the above?


Here is my understanding of what's going on here. Although I am kinda new to this also.



Code:
NSFileManager *fileManager = [NSFileManager defaultManager];
Returns the default NSFileManager object for the file system. So now you have a file manager object that you can use all the file mangager instance methods on. You can find all of those in the API. Stuff like copying and writing and reading and pretty much anything you would want to do with a file.


Code:
NSError *error;
In the code above, this is just creating a pointer to an NSError Object that you aren't doing anything with. It will probably give you a warning saying it's not being used. But it will still run.


Code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
This bit creates an array with two entries in it. They each contain a full path (with ~ (~user/) expanded because of the BOOL YES. Then you assign the first entry of the array to the string *documentsDirectory. So now documentsDirectry is a charactor string that is an address to your documents directory. You can see this directory by looking in you iPhone Simulator. Its at ~user/Library/Application Support/iPhone Simulator/User/Applications/ ... Your App (which will be represented by a bunch of numbers)/. Inside there you should see you Documents directory. That is the location you are pointing at.



Code:
self.pathToUserCopyOfPlist = [documentsDirectory stringByAppendingPathComponent:@"appData.plist"];
Here it seem you must have an NSString already created called pathToUserCopyOfPlist. And you are taking the documentsDirectory string from above and sticking a file name on the end of it. This would be a file you are expecting to find in the documents directory. The command stringByAppendingPathComponent is a nice one because it will determine if it needs to stick a "/" slash in the name. If the directory string was to end in "/Documents/" then the string it appends would be just "appData.plist" but if the documents directory ended in just "/Documents" then the string it appends would be "/appData.plist".

But like the post above, this isn't actually doing anything yet. Now you need to tell it what you want to do with your file. If it exists.

Mark A
fxshot is offline   Reply With Quote
Old 10-02-2009, 04:18 AM   #4 (permalink)
ranjeet_bhatta
 
Join Date: Sep 2009
Posts: 16
afixi.ranjeet is on a distinguished road
Default Data transfer

Thank you fxshot....
I actually I want to transfer data from a pickerview(which is a sub-view) to its parent view.That's why I downloaded it from a site.But I am very new to it.So
felt very difficult to understand......
So if you have any alternate way please help me.
afixi.ranjeet is offline   Reply With Quote
Old 10-05-2009, 07:03 AM   #5 (permalink)
iOS Dev
 
Join Date: Aug 2009
Location: Chandigarh
Posts: 39
Jango is on a distinguished road
Send a message via Skype™ to Jango
Question iPhone file Manager

Quote:
Originally Posted by fxshot View Post
Here is my understanding of what's going on here. Although I am kinda new to this also.



Code:
NSFileManager *fileManager = [NSFileManager defaultManager];
Returns the default NSFileManager object for the file system. So now you have a file manager object that you can use all the file mangager instance methods on. You can find all of those in the API. Stuff like copying and writing and reading and pretty much anything you would want to do with a file.


Code:
NSError *error;
In the code above, this is just creating a pointer to an NSError Object that you aren't doing anything with. It will probably give you a warning saying it's not being used. But it will still run.


Code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
This bit creates an array with two entries in it. They each contain a full path (with ~ (~user/) expanded because of the BOOL YES. Then you assign the first entry of the array to the string *documentsDirectory. So now documentsDirectry is a charactor string that is an address to your documents directory. You can see this directory by looking in you iPhone Simulator. Its at ~user/Library/Application Support/iPhone Simulator/User/Applications/ ... Your App (which will be represented by a bunch of numbers)/. Inside there you should see you Documents directory. That is the location you are pointing at.



Code:
self.pathToUserCopyOfPlist = [documentsDirectory stringByAppendingPathComponent:@"appData.plist"];
Here it seem you must have an NSString already created called pathToUserCopyOfPlist. And you are taking the documentsDirectory string from above and sticking a file name on the end of it. This would be a file you are expecting to find in the documents directory. The command stringByAppendingPathComponent is a nice one because it will determine if it needs to stick a "/" slash in the name. If the directory string was to end in "/Documents/" then the string it appends would be just "appData.plist" but if the documents directory ended in just "/Documents" then the string it appends would be "/appData.plist".

But like the post above, this isn't actually doing anything yet. Now you need to tell it what you want to do with your file. If it exists.

Mark A

Hi,
I read your post...
I was wondering if apple provides access to different filetypes in iphone
like in hard disk manager.

Can we access the hard drive info of the iphone. if yes then how..
Jango 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: 459
13 members and 446 guests
Domele, Duncan C, Feldspar, MacBook MH, Objective Zero, patapple, peterwilli, pipposanta, PixelInteractive, Punkjumper, SLIC, taylor202, Today's Posts
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,694
Threads: 94,137
Posts: 402,950
Top Poster: BrianSlick (7,990)
Welcome to our newest member, peterwilli
Powered by vBadvanced CMPS v3.1.0

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