Re: Managing image loading
Re: Managing image loading
- Subject: Re: Managing image loading
- From: Leonardo <email@hidden>
- Date: Sat, 08 Feb 2014 12:58:56 +0100
- Thread-topic: Managing image loading
Thank you Jens. I have found the proper way to manage that.
When the user imports a new image, I quickly copy the image to a temporary
folder, then I add this latest file reference to the document¹s
NSFileWrapper.
I just create the file¹s fileWrapper using its URL, so I do not read its
content and create the fileWrapper by the NSData.
When the users saves the document, automatically the filesWrappers get
written to the disk, within the document filePackage.
And when I close the document, I remove the temp folder.
That¹s fine.
I had to scratch my head at managing the undo, but I found a solution here
too.
When the user undo the import of an image, if the images has been never
saved, so it is still within the temporary folder, I just remove the image
file reference from the fileWrapper. Instead, if the image has already been
saved, so it is within the file package, I copy its file to the temporary
folder and remove its reference from the fileWrapper. So when the user saves
the doc, the image file get removed from the doc filePackage. And if the
user invokes the undo, I add the temp image file to the fileWrapper.
It sounds complicated but it works well.
Why do I use a temporary folder? Because if the user imports an image file
then he tries to delete the original image file, the OS tells him that he
can¹t delete that file in use. That could be annoying.
Why don¹t I add the file¹s NSData to the fileWrapper but I add just its URL
reference? Because I don¹t really know whether the fileWrapper uses the disk
or keeps the NSData in memory. So in case of a 1GB file I do not engulf the
app.
I hope I have designed a good architecture.
Regards
-- Leonardo
Da: Jens Alfke <email@hidden>
Data: Tue, 4 Feb 2014 11:47:35 -0800
A: Leonardo <email@hidden>
Cc: <email@hidden>
Oggetto: Re: Managing image loading
On Feb 4, 2014, at 9:03 AM, Leonardo <email@hidden> wrote:
> - When the user imports a new image, I add its NSData to the NSFileWrapper
> [docFileWrapper addRegularFileWithContents:imgData
> preferredFilename:@"image.png"];
> and retain the NSImage. So I can draw the NSImage at any time.
You don't need an NSFileWrapper for that. I would just use NSFileManager to
copy the file, and NSData methods to read/write the file. I have no idea
whether NSFileWrapper caches the file contents in memory or not.
Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden