iOS development: Invoking the OC library in Swift

Source: Internet
Author: User

first enumerate the OC repositories used in this project:

    • Mbprogresshud: Translucent cue, loading animation, etc.
    • Sdwebimage: Gallery of picture downloads and caches
    • Mjrefresh: drop-down refresh, pull-up load
    • Alamofire.xcodeproj and Swiftyjson.xcodeproj are the libraries of Swift, and this blog mainly records calls to the above 4 OC libraries.

The first step: drag the OC repository into our projec, such as.

Step Two: create a new header file to refer to the OC Library. For example, select the header file in the object library and drag it to the root of project.

Note the naming conventions for header file names: project name-brdging-header.h, such as.

Step three: after the new is complete, use #import to refer to the OC Library, such as.

Fourth Step: This step is more important, select Sexygallery > Build Settings > Enter Swift Compiler in the search box > select objective-c bridging Header &G T Type the file name just now Sexygallery-bridging-header.h > Command + S to save.

After the successful import, next Test how to reference, and then call the Mjrefresh library as an example, as long as the Uirefreshcontrol declaration variable can be compiled can pass, it means that can be called normally, the use of methods see Mjrefresh related documents:

import uikitimport swiftyjsonimport alamofireclassGallerylistviewcontroller:uiviewcontroller, Uicollectionviewdatasource, uicollectionviewdelegateflowlayout { Let Refreshcontrol= Uirefreshcontrol ()//Drop-down refresh@IBOutlet weak var collectionview:uicollectionview!Overridefunc viewdidload () {super.viewdidload () Self.configurerefresh ()}//set dropdown and up refreshfunc Configurerefresh () {Self.collectionview?. Header = Mjrefreshnormalheader (refreshingblock: {)inchPrint ("Header") self. RefreshData () Self.collectionview?. header.endrefreshing ()}) Self.collectionview?. Footer =Mjrefreshautofooter (refreshingblock: {()inchPrint ("Footer") Self.loaddata () Self.collectionview?. footer.endrefreshing ()}) }}

Finish!

iOS development: Invoking the OC library in Swift

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.