Note that there are some explanatory texts on larger screens.

plurals
  1. POload data from cache with NSURL doesn't work
    primarykey
    data
    text
    <p>i'm trying to load a photo from my cache directory.</p> <p>this is the code where i write the photo into a cache folder:</p> <pre><code>+(BOOL)writeAData:(NSData *)imageData atURL:(NSURL *)fileUrl { return [imageData writeToURL:fileUrl atomically:YES]; } </code></pre> <p>this code works fine, but i have problems when i try to load the code from the cache folders:</p> <p>i use the method initWithContentsOfURL inside a block:</p> <pre><code> NSData *imageData = [[NSData alloc] initWithContentsOfURL:self.imageUrl]; </code></pre> <p>this is the format of url</p> <pre><code>file://localhost/Users/MarcoMignano/Library/Application%20Support/iPhone%20Simulator/6.1/Applications/0E8E54D8-9634-41CF-934B-A7315411F12F/Library/Caches/image_cache/Meyer%20Library.jpg </code></pre> <p>the URL is correct, but when i try to use the method above i get this error:</p> <pre><code> ..... [__NSCFString isFileURL]: unrecognized selector sent to instance 0x8a0c5b0 ..... </code></pre> <p>that is the code when i take the url of my model:</p> <pre><code>-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; self.photos = [PhotoAlreadyDisplayed getAllPicture]; } -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([sender isKindOfClass:[UITableViewCell class]]) { NSIndexPath *indexPath = [self.tableView indexPathForCell:sender]; if (indexPath) { if ([segue.identifier isEqualToString:@"Show Image"]) { if ([segue.destinationViewController respondsToSelector:@selector(setImageUrl:)]) { NSURL *url = [[self.photos objectAtIndex:indexPath.row] valueForKey:@"url"]; [segue.destinationViewController performSelector:@selector(setImageUrl:) withObject:url]; [segue.destinationViewController setTitle:[self titleForRow:indexPath.row]]; } } } } } </code></pre> <p>whats wrong with the URL? how can i fix it? thank you</p> <p><strong>i have find the solution:</strong> when i load the url for the model, i need to initialize the url using fileURLWithPath method:</p> <pre><code>NSURL *url = [NSURL fileURLWithPath:[[self.photos objectAtIndex:indexPath.row] valueForKey:@"url"]]; </code></pre> <p>Now all works fine, thank you so much for yours help</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload