Reputation: 2040
How can I convert NSUrl
to QLPreviewItem
? In the QLPreviewItem
.h, it is written that the below category makes NSURL
instances as suitable items for the Preview Controller:
@interface NSURL (QLPreviewConvenienceAdditions) <QLPreviewItem>
How can I use it if in my code I have:
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index
{
NSString *path=[[NSBundle mainBundle] pathForResource:[filenamesArray objectAtIndex:index] ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
return //QLpreview item from URL;
}
Upvotes: 0
Views: 1485
Reputation: 3816
Or using Swift:
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
let resumeUrl = Bundle.main.url(forResource: "resume", withExtension: "docx")!
return resumeUrl as QLPreviewItem
}
Upvotes: 1
Reputation: 41
You can just return the NSURL, it will work.
I've been using this:
if([downloadData writeToURL:self.fileUrl options:NSDataWritingAtomic error:&error])
(...)
And then I used the same URL as QLPreviewItem:
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
return self.fileUrl;
}
Upvotes: 2