Multi-language coexistence period, must be mixed into a way to achieve coexistence and OC Swift languages in more than shadow turned out to be so simple
The first scenario, App achieved mixed
- Create a bridge file
*.h
a new bridge file,New File
chooseHeader File
to create a - Specifies the bridge file
project->targets->Build Setting->All->Swift Compilter General->Objective-C-Bridging-Header
to specify the new bridge just the file
- OC import header file (
*.h
) to the bridge file
such as:#import "Log.h"
- Complete the call
inSwift
directly call the file
Note: Create a file for the first time in OC Swift project, Xcode
it will automatically be prompted to create a bridge file
The second scene, Framework implemented in mixed
- Creating
Famework
Once created will generate a header file with the same name*.h
- The OC header (
*.h
) as the public header file
project->targets->Build Phases->Headers->Public
directly dragged
- OC import header file (
*.h
) to a header file of the same name
, such as:#import "Log.h"
- Complete the call
in externalSwift
files called directly
Note: external classes and methods must bepublic
marked before visit
The third scenario, Pod
the package realized mixed
After completing the second scenario, add the *.podspec
files to achieve Pod
package
- Generation
*.podspec
to run the commandpod spec create [name]
generates*.podspec
a file Editing
*.podspec
in*.podspec
in the header file OC (*.h
set) discloses headers
such as:spec.public_header_files = "Log.h"
#完整的文件信息 Pod::Spec.new do |spec| spec.name = "OCSwiftFramework" spec.version = "0.0.1" spec.summary = "OCSwiftFramework" spec.description = <<-DESC OCSWiftFramework DESC spec.homepage = "https://www.ichochy.com" spec.license = "MIT" # spec.license = { :type => "MIT", :file => "FILE_LICENSE" } spec.author = { "MLeo" => "[email protected]" } spec.platform = :osx spec.osx.deployment_target = "10.10" spec.source = { :git => "https://github.com/iChochy/HelloWorld.git", :tag => "#{spec.version}" } spec.source_files = "**/*.{h,m,swift}" spec.exclude_files = "Info.plist" spec.public_header_files = "Flog.h" spec.swift_version = "4.2" end
- Verify
*.podspec
the Run commandpod lib lint
to complete verification - Complete call a. Run command
pod trunk push [NAME.podspec]
to complete the publication
b.Podfile
Addpod "[name]"
c. Run the commandpod install
to complete thepod
installation. d After installation directly call
Note: Availablepod "[name]", :path => "[path]"
local designated
GitHub:
HelloWorld:https://github.com/iChochy/HelloWorld.git
Contact information:
E-mail: [email protected]
website: https://www.ichochy.com
source file: https://www.ichochy.com/blog/2019/09/04/OC and mixed Swift - achieve three scenarios way .html