Introduction to AppleWatch Development Eight processing of picture caches in--watch
Since iwatch has a large gap in storage and performance with the iphone, it requires developers to have higher performance optimizations for the program, downloading and transmitting images, which is a non-time process in watch operations, so watchOS provides us with a framework for caching images And the interface and use are very simple.
The method of caching pictures in watchOS is encapsulated in the Wkinterfacedevice class, where the addition of pictures into the cache is as follows:
Add a UIImage object to the cache directory, set name, and when we set the picture, we can set the public func addcachedimage (Image:uiimage, name:string) directly through name. bool//add a data picture into the cache directory, set name, when we set the picture, we can set the public func addcachedimagewithdata (Imagedata:nsdata, name) directly through name: String)-bool//The return value of the above two methods is used to determine if the cache is successful because the size of the watch cache directory is limited and may fail
Similarly, we can also delete the cached image data:
Delete a picture data by name public func removecachedimagewithname (name:string)//delete all picture data in cache directory public func Removeallcachedimages ()
We can also get the name value of all cached pictures in the following way:
The following function returns a dictionary, String is the name value of the cached picture, NSNumber is the corresponding picture size, in bpublic var cachedimages: [String:nsnumber] {get}
Note: The size of the system cache directory is 20M, and if the cache fails, you can try to erase the old cache.
Introduction to AppleWatch Development Eight processing of picture caches in--watch