Use of proxies in swift

Source: Internet
Author: User


1. Define an agreement first.


 
Protocol httptoolprorocol {// 1. The proxy method that passes the dictionary returned by the server to the caller func didrecieveresults (Result: nsdictionary )}



2. Define a proxy Property
 
// 2. Declare the proxy property var delegate: httptoolprorocol?


3. Determine whether the proxy implements the proxy method. If the proxy deserializes the dictionary returned by the server, it is passed to the caller.

// 3.3.1 deserialize the returned data var jsonresult: nsdictionary = nsjsonserialization. jsonobjectwithdata (data, options: nsjsonreadingoptions (), error: nil) as nsdictionary // 3.4 transmits the dictionary returned by the server to the caller if (data) {self. delegate ?. Didrecieveresults (jsonresult )}

4. Implement proxy Methods

 
// Proxy method func didrecieveresults (Result: nsdictionary ){}



The specific sequence is similar to OC. This article is for reference to children's shoes who are new to SWIFT. I am also new to SWIFT. You are welcome to leave a message to learn and make progress together.

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.