Xcode 9.4.1
Create a Framework
1. New construction
Open Xcode, Command +n create a new project, select Cocoa Touch Framework, click Next and name it StringExtension.
2. Create a file
Swift is not intended to be exposed; test. swift is intended to be exposed to calls.
Classes or methods that need to be exposed for external calls must be accompanied by keywordspublic
.
3.Scheme
Set toshared
Use 4.Carthage
buildFramework
Terminal into the project directory, execute the following code
$ carthage build --no-skip-current
Copy the code
When we’re done, we’ll find a Carthage folder in the directory where our Framework is located.
Upload the Framework to Github
1. Create a warehouse
2. Initialize the warehouse
Terminal into the project directory, execute the following code
$ echo "# StringExtension" >> README.md
$ git init
$ git add README.md
$ git commit -m "first commit"
$ git remote add origin https://github.com/Geselle-Joy/StringExtension.git
$ git push -u origin master
Copy the code
3. Add gitignore
$git add. Gitignore $git commit -m "add gitignore" $git pushCopy the code
4. Add project files
$ git add .
$ git commit -m "add StringExtension"
$ git push
Copy the code
5. Add a version tag
$git tag 1.0.0 $git pushCopy the code
At this point, the framework we created has been uploaded to Github.
Call the Framework we created
1. Create a new project with Xcode
Create the project and CD it to the project directory
2. Create an empty Carthage file
$ touch Cartfile
Copy the code
3. Edit Cartfile files
Edit the Cartfile file and enter the following
github "Geselle-Joy/StringExtension"
Copy the code
Version of the meaning
~> 3.0 Indicates that version 3.0 is used but later than 4.0. For example, 3.5, 3.9 == 3.0 Indicates that version 3.0 is used. >= 3.0 Indicates that version 3.0 or later is usedCopy the code
4. Save and close the Cartfile file and run the following commands on the terminal
$ carthage update --platform iOS
Copy the code
The installation process is as follows
$ testss carthage update --platform iOS
*** Cloning StringExtension
*** Checking out StringExtension at "1.0.0"
*** xcodebuild output can be found in /var/folders/8w/s8bn_8c56p9czz75nqdqmp2m0000gn/T/carthage-xcodebuild.ecw6rz.log
*** Building scheme "StringExtension" in StringExtension.xcodeproj
Copy the code
Carthage will download and compile the third party libraries you need. When the command is executed, a folder named Carthage and Cartfile. Resolved files will appear in your project folder.
In ~ / Carthage/Build/iOS folder can see our own StringExtension. Create a framework.
5. Import the framework
Open your project, select Target, then General above, and drag the required framework files into Linked Frameworks and Binaries.