一、workspace创建
1.创建Workspace工作空间
File -> New -> Workspace...
workspace
2.创建主项目(MainProject)、静态库(TestStatic)、动态库(TestFramework)
打开WorkspaceTest.xcworkspace
- 添加方式1(新建项目,添加到WorkspaceTest文件夹下,并且添加到
WorkspaceTest.xcworkspace
工作空间中)
File -> New -> Project... -> Single View Application
File -> New -> Project... -> Cocoa Touch Static Library
File -> New -> Project... -> Cocoa Touch Framework
-
添加方式2(添加已存在的主项目或动态、静态库)
二、主项目引用动态库、静态库
1.在主工程中添加依赖库
TARGETS -> Build Phases -> Link Binary With Libraries
2.添加头文件
TARGETS -> Build Settings -> Header Search Paths
3.调用动态库、静态库方法
三、使用cocopods
创建Podfile
文件,内容格式如下
platform :ios, '10.0'
#工作空间名称
workspace 'WorkspaceTest.xcworkspace'
#公用三方库
def shared_pods
use_frameworks!
pod 'Alamofire'
pod 'SnapKit'
pod 'IQKeyboardManagerSwift'
end
#主项目
target 'MainProject' do
#主项目路径
project 'MainProject/MainProject.xcodeproj'
shared_pods
pod 'RxSwift', '~> 5'
pod 'RxCocoa', '~> 5'
end
#动态库
target 'TestFramework' do
#动态库路径
project 'TestFramework/TestFramework.xcodeproj'
shared_pods
end
#静态库
target 'TestStatic' do
#静态库路径
project 'TestStatic/TestStatic.xcodeproj'
shared_pods
end
执行pod install
四、添加资源文件
1.添加Bundle
2.加入资源
3.图片加载
open class TestImageBundle {
open class func podBundleImage(named: String) -> UIImage? {
let podBundle = Bundle(for: TestImageBundle.self)
if let url = podBundle.url(forResource: "TestImageBundle", withExtension: "bundle") {
let bundle = Bundle(url: url)
return UIImage(named: named, in: bundle, compatibleWith: nil)!
}
return nil
}
}
网友评论