# Building Libraries for iOS Componentization by using cocoaPods :::info :bulb: **This content discusses the modularization of partial code components, utilizing the CocoaPods method to manage the code separately, gradually solving the issues of CPU loading, code readability etc...** **By modularizing the project code, not only can we clearly separate code functionalities for a more readability, we can also alleviate CPU load during system initialization process.** **This helps reduce CPU burden, and the components can be imported as needed to achieve the goal of modularization.** **The following content is primarily based on GitLab.** ::: ## :book:Before setting up a library, it's necessary to create an index repository. #### 1.Firstly, check the index repository on the current system. pod repo or pod repo list if you want to remove repo, you can alse call pod repo remove (remote index repository) #### 2. Create a local index repository then link it to the recently created remote index repository. Remote index repository must have a master branch, so you can add a readme file. cd (local folder) pod repo add indexRepository(CLThirdTestSpec) gitlab address(https://gitlab.com/chuan800418/clthirdtest.git) ![截圖 2023-11-29 下午3.52.55](https://hackmd.io/_uploads/SyeEJAPNra.png) ![截圖 2023-11-29 下午3.50.34](https://hackmd.io/_uploads/rJlPpvNST.png) #### 3. Start to created local private repository pod lib create repository(CLThirdTest) ‼️ This **repository(CLThirdTest)** is the place which stroe the code, don't mess up with **remote index repository(CLThirdTestSpec)** ![截圖 2023-11-29 下午4.03.07](https://hackmd.io/_uploads/r1DSgdNST.png) You can just choose the answer that you want! Relust of folder: ![截圖 2023-11-29 下午4.04.49](https://hackmd.io/_uploads/ByAjldVBp.png) then you can call pod install once time. pod install #### 4. Configure "podspec" <1> ‼️ s.homepage = 'https://gitlab.com/chuan800418/clthirdtest' <2> ‼️ s.source = { :git => 'https://gitlab.com/chuan800418/clthirdtest.git', :tag => s.version.to_s, :branch => "master" } <3> ‼️ s.version = '0.0.xxx' Version here need to be set as same as the tag version(next process). ![截圖 2023-11-29 下午6.45.48](https://hackmd.io/_uploads/SyOv854rp.png) #### 5. Local check After we push the code we need to make once local check pod lib lint --private --allow-warnings ![截圖 2023-11-29 下午4.31.16](https://hackmd.io/_uploads/B1aGwOVB6.png) #### 6. Push to remote <1> you can choose the command line: pod install git status git add . git commit -m "init" git remote add origin git push -u origin master <2> Source Tree ![截圖 2023-11-29 下午4.24.16](https://hackmd.io/_uploads/BJp8SuEBa.png) ![截圖 2023-11-29 下午4.24.35](https://hackmd.io/_uploads/rJ0LH_VB6.png) #### 7. Tag ‼️ Tag version here need to as same as "podspec"!!!!!!! git tag version number- git push --tags ![截圖 2023-11-29 下午4.37.06](https://hackmd.io/_uploads/B1SSdu4Sp.png) #### 8. remote check make remote check one time pod spec lint --private --allow-warnings ![截圖 2023-11-29 下午4.38.26](https://hackmd.io/_uploads/SkG6d_4S6.png) #### 9. release pod repo push indexRepository(CLThirdTestSpec) repository.xxxpodspec(CLThirdTest.podspec) --allow-warnings ![截圖 2023-11-29 下午6.01.13](https://hackmd.io/_uploads/HywW3FVHa.png) Then excute pod repo update pod search repository(CLThirdTest) #### 10. Ustage finally we can pod your package into others project like: ![截圖 2023-11-29 下午6.10.55](https://hackmd.io/_uploads/H1CNCtNr6.png) And run pod install ![截圖 2023-11-29 下午6.11.45](https://hackmd.io/_uploads/S1Aw0FNHT.png) ‼️ Add Code Here ‼️ One another thing: Any code you want to release in Xcode need keywords "public" ![截圖 2023-11-29 下午6.13.56](https://hackmd.io/_uploads/rJbek9ESa.png) #### 11. public repository If you want to put yours package to cocoapos public repository <1> Execute: pod trunk register Email Address(chuan800418@gmail.com) userName(chuan800418) <2>Then go to verify ![截圖 2023-11-29 下午6.21.09](https://hackmd.io/_uploads/B1Z7-9VHa.png) ![截圖 2023-11-29 下午6.21.16](https://hackmd.io/_uploads/SkNXb5NSp.png) After success execute: pod trunk push repository.xxxpodspec(CLThirdTest.podspec) --allow-warnings ![截圖 2023-11-29 下午6.26.47](https://hackmd.io/_uploads/r1PNz5EB6.png) --- ## ErrorHandling If some project too old and Xcode 1.4.3 doesn't including file 'arc' need to execute the modify below: 1. <1> System Setting -> privacy And Security -> Full Disk Access ![截圖 2023-11-29 下午9.49.07](https://hackmd.io/_uploads/rkxDbaVBa.png) <2> cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ sudo mkdir arc cd arc sudo git clone https://github.com/kamyarelyasi/Libarclite-Files.git . 2. If command line show error msg below, please excute pod repo remove (remote index repository) and cd (local folder) pod repo add indexRepository(CLThirdTestSpec) gitlab address(https://gitlab.com/chuan800418/clthirdtest.git) ![截圖 2024-04-25 下午7.29.29](https://hackmd.io/_uploads/ByjPbTwb0.png)