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.