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