Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

NSFileManager

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

Can someone help me to understand the above?
Post edited by afixi.ranjeet on

Replies

  • stroodlestroodle Posts: 5New Users
    afixi.ranjeet;129097 said:
    I can't understand the purpose of the following code:
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 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).
  • fxshotfxshot Posts: 75Registered Users
    afixi.ranjeet;129097 said:
    I can't understand the purpose of the following code:
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, 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.



    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.


    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.



    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.



    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
    Check out my app 'Dress Up Studio' on the iTunes Store -

    http://itunes.apple.com/us/app/dress...359728350?mt=8
  • afixi.ranjeetafixi.ranjeet Posts: 16Registered Users
    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.
  • JangoJango Posts: 39Registered Users
    fxshot;129920 said:
    Here is my understanding of what's going on here. Although I am kinda new to this also.



    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.


    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.



    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.



    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..
Sign In or Register to comment.