Swift learns the second practice--swift project time Movie

Source: Internet
Author: User

Swift learns the second practice--swift project time Movie

A previous OC Practice project was re-written with Swift, as the compatibility of the update to Swift for the Xcode version is also changing, and this version applies to xcode6.1.

This project uses Swift to encapsulate HTTP in the iOS official SDK, using Swift's method of loading the network images asynchronously. Practice the method of using Swift to operate the interface layout, jump interface and so on.

The following is the core code for the encapsulated download class:

Private var httpconnection:nsurlconnection?class zyhhttprequset: nsobject, Nsurlconnectiondatadelegate{    var requesturl:string?    var  downloaddata:nsmutabledata=nsmutabledata ()     var isDownloadSuccess:Bool?     var delegate:ZYHHttpRequestDelegate?    class func  Requestformurl (url:nsstring)->zyhhttprequset{        var  Oldrequest:zyhhttprequset?=zyhhttprequestmanager.sharedhttprequestmanager (). Requestforkey (URL)          if  (Oldrequest != nil) {             PRINTLN ("This task exists")              return oldRequest!        }         //New Download Task   &Nbsp;     var request:zyhhttprequset=zyhhttprequset ()          request.requestUrl=url         Request.startrequesturl (URL)          Zyhhttprequestmanager.sharedhttprequestmanager (). AddTask (Request, key: url)          return request    }         func stop () {        if httpconnection != nil  {            httpconnection?. Cancel ()             httpconnection = nil         }    }         //Start Download Request     private func startrequestURL (url:nsstring) {        if httpconnection != nil  {            httpconnection!. Cancel ()             httpConnection==nil         }        //Creating a Connection object          var request=nsurlrequest (Url: nsurl (string: url)!)         httpconnection=nsurlconnection (request: request,  Delegate: self)             }     //method     func connection in the rewrite protocol (connection: nsurlconnection,  Didreceiveresponse response: nsurlresponse)  {         downloaddata.length=0    }     func connection (Connection: nsurlconnection, didreceivedata data: nsdata )  {        downloaddata.appenddata (data)     }     func connectiondidfinishloading (connection: nsurlconnection)  {         isDownloadSuccess = true         delegate!. Zyhhttprequestsuccsee (self)          Zyhhttprequestmanager.sharedhttprequestmanager (). Removetaskfromurl (self.requesturl!)     }    func connection (connection: nsurlconnection,  Didfailwitherror error: nserror)  {        println ("Load failed ")         println (Error)          self.isdownloadsuccess=false   &nbSp;    zyhhttprequestmanager.sharedhttprequestmanager (). Removetaskfromurl (self.requestUrl!)     }                 }protocol zyhhttprequestdelegate{    func zyhhttprequestsuccsee ( Request:zyhhttprequset)}

Project section:


GitHub Source Address: Https://github.com/ZYHshao/SwiftMovie

One of the mistakes, welcome advice, Hope in the exchange, continuous progress!

Swift learns the second practice--swift project time Movie

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.