I'm storing some objects in Core Data. My NSManagedObject subclass has a urlString property (which I get from the original source url's absoluteString).
When I create or update my NSManagedObjects, I grab the absoluteString for the URL and store it. Now my managed object subclass has a URL property which I compute using the urlString.
-(NSURL*)URL
{
return [NSURL URLWithString:self.urlString];
}Now, this works only if the file doesn't have a space. absoluteString gives an escpaed string I believe, so whether or not the file name contains a space shouldn't matter?
When I log out the returned URL, it matches the urlString, but when I try to access anything on the URL, I get an error:
Error Domain=NSCocoaErrorDomain Code=260 "The file “my file.txt” couldn’t be opened because there is no such file."
Now I did a little test with the original URL against the one returned from URL:
NSURL *originalURL = //grabbed from the data used to create the NSManagedObject subclass..
myManagedObject.urlString = originalURL.absoluteString; //<---set the urlString property.
NSURL *computedURLFromAbsoluteString = self.URL;
if ([computedURLFromAbsoluteString isEqual:originalURL])
{
NSLog(@"Equal."); //<--Logs out.
}Now, if I use the originalURL....I can access the resource, but if I use the URL returned from the URL method, I get the error even though the URLs are equal.
These files are part of my app's sandboxed container so I see no reason why I should be denied permission (error doesn't say that it is a permissions error either, it says the file doesn't exist) and it also seems quirky that this problem only occurs if the file has a space in its name. Am I missing something? I guess I can try to store bookmark data, but I'd rather not do that for every file when creating these managed objects.