Introduction to AppleWatch Development Eight processing of picture caches in--watch

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.