First step: Create and configure Bridging-header.h
Swift is mixed with OC with an. h file, which uses bridging-header.h and then sets the project's build Settings--swift compiler--objective-c bridging The Header content is demoapp/bridging-header.h, which is related to the bridging-header.h position, starting at the root directory of the project Objective-c bridging The Header option writes the Bridging-header.h relative path.
Step two: Third party project Dependencies
To the third party project dependence, at first I intend to use cocoapods, but the process twists and turns, finally has been reported
[OBJC] View plain copy <span style= "FONT-SIZE:14PX;" >ld:218 duplicate symbols for architecture i386 Clang:error:linker command failed with exit code 1 (use-v to) Invocation) </span> I also have no way to copy the third party project source code into their own projects, the image can also see my copy of the Afnetworking project, and then add the source code to build Phases--compile Sources inside
Step Three: Modify Bridging-header.h
Write #import "AFNetworking.h" in Bridging-header.h step Fourth: Invoke OC
After the previous work is done, we can invoke the function of the third party project.
[objc] View plain copy // // viewcontroller.swift // DemoApp // // created by jiezhang on 14/10/24. // copyright (c) 2014 year jiezhang. all rights reserved. // import uikit class viewcontroller: UIViewController { @IBOutlet weak var weatherInfo: UITextView! override func viewdidload () { super.viewdidload () updateweatherinfo () } override func didreceivememorywarning () { super.didreceivememorywarning ()