Saturday, December 7, 2013

Type how convert NSString NSURL type (involving file deletion)?

The thing is: I use the tutorial is a bit old, the tool is xcode 4.2, the machine is X 10.7.3. Part of the grammar book has been abandoned, one of which is to delete the file method - (BOOL) removeFileAtPath: (NSString *) path handler: (id) handler has been deprecated, and its replacement is - (BOOL) removeItemAtURL: ( NSURL *) URL error: (NSError **) error problem is how do I put that (NSString *) path is converted into (NSURL *) URL. Examples of relevant code is as follows:

NSString * fName = @ "testfile";

if ([fm removeFileAtPath: fName handler: nil] == NO)
{
NSLog (@ "File removal failed!");
return 6;
}

I changed it so it can not be deleted, not sure right

NSString * fName = @ "testfile";

if ([fm removeItemAtURL: [NSURL URLWithString: [fName stringByAppendingFormat: fName]] error: nil] == NO)
{
NSLog (@ "File removal failed!");
return 6;
}



Or file conversion problem is the problem?
Reply:
path is the path to your file, not the file name.

Assuming your file is packaged in the master project:

NSString * filePath = [[NSBundle mainBundle] pathForResource: "testFile" ofType: "xml"];
Reply:
cited a floor reply:
path refers to a path to your file, not the file name.

Assuming your file is packaged in the master project:

NSString * filePath = [[NSBundle mainBundle] pathForResource: "testFile" ofType: "xml"];


My files and programs in the same directory
You write what is meant by the above method
Reply:
Have to add the path, not just the file name
Reply:
reference to the third floor of the reply:
have to add the path, not just the file name

My files and programs in the same directory, and other operations are no problem
Reply:
references, 4th Floor reply:
reference to the third floor of replies:

Have to add the path, not just the file name

My files and programs in the same directory, and other operations no problem

Road King did not write the first file
To add a second file name suffix
If the program is packaged inside a building on the method
Reply:
references, 5th Floor reply:
references, 4th Floor reply:

3rd Floor cited reply:

Have to add the path, not just the file name

My files and programs in the same directory, and other operations no problem

Road King did not write the first file
To add a second file name suffix
If the program is packaged inside a building on the use of the method

Which convert it? Before that I used? - (BOOL) removeItemAtURL: (NSURL *) URL error: (NSError **) error method is NSURL type a URL,
Reply:
references, 5th Floor reply:
references, 4th Floor reply:

3rd Floor cited reply:

Have to add the path, not just the file name

My files and programs in the same directory, and other operations no problem

Road King did not write the first file
To add a second file name suffix
If the program is packaged inside a building on the use of the method

This is such a change

NSString * filePath = [[NSBundle mainBundle] pathForResource: @ "testfile" ofType: @ "xml"];


if ([fm removeItemAtURL: [NSURL URLWithString: [filePath stringByAppendingFormat: filePath]] error: nil] == NO)
{
NSLog (@ "File removal failed!");
return 6;
}

Through the program execution, but the file is still not deleted
Reply:
By
- (BOOL) removeItemAtPath: (NSString *) path error: (NSError **) error
Reply:
Or use
[Fm removeItemAtURL: [NSURL fileURLWithPath: (NSString *) path]] try, path is the path to your previous file.
Reply:
Without conversion. On the 8th floor with.
Reply:
referenced 8th Floor reply:
with
- (BOOL) removeItemAtPath: (NSString *) path error: (NSError **) error

reference to the 9th floor Reply:
or use
[Fm removeItemAtURL: [NSURL fileURLWithPath: (NSString *) path]] try, path is the path to your previous file.


two are OK, thank you, thank you
Reply:
referenced 8th Floor reply:
with
- (BOOL) removeItemAtPath: (NSString *) path error: (NSError **) error


This can be

No comments:

Post a Comment