Preventing merge conflicts with XcodeGen

Hello, Habr! In anticipation of the start of the "iOS Developer. Professional" course, we have prepared for you a traditional translation of useful material. We also invite those who wish to an online meeting with the course teacher , where you can ask the teacher any questions you are interested in about training.



And finally, we suggest watching the recording of the webinar
"Writing an application using SwiftUI and Combine".






I - Introduction

In this article, we'll look at a solution to instantly resolve merge conflicts in a file.xcodeproj



, which is one of the most time-consuming issues facing iOS and macOS development teams today.





Image source: https://medium.com/@kautilyasave/xcode-merge-conflict-debugging-5904c7e0cc59
Image source: https://medium.com/@kautilyasave/xcode-merge-conflict-debugging-5904c7e0cc59

, .





II -

1. XcodeGen

yonaskolb/XcodeGen

github.com





XcodeGen β€” , Swift, Xcode- .





XcodeGen Brew. brew install xcodegen ( ).





2.

. , ( ), , , CI . .





, , , XcodeGen, , .





Example project structure

, :









  • Carthage-













III -

Sample app screens

1.

(sample project), , carthage-. makeProject.sh



. , .





Installing the project (Brew, Carthage, XcodeGen, dependencies ...)
(Brew, Carthage, XcodeGen, …)

2. XcodeGen

XcodeGen ( ) project.yml ( ).





This file will serve as the specification for our .xcodeproj
.xcodeproj

XcodeGen/project.yml



: :





name: GoodToGo
options:
  bundleIdPrefix: com.GoodToGo
  xcodeVersion: '12.0.1'
  deploymentTarget: '12.0'
  groupSortPosition: top
  generateEmptyDirectories: true
  findCarthageFrameworks: true
  minimumXcodeGenVersion: '2.18.0'
      
      



  .xcodeproj



β€” GoodToGo



β€” , β€” com.GoodToGo



β€” , Xcode, …





3. XcodeGen

, , xcodegen -s ./XcodeGen/project.yml -p ./



.





, ./XcodeGen/project.yml



β€” . /, .





XcodeGen / project.yml: First run
XcodeGen/project.yml:

, . , !





, :





, … , , . , project.yml.





4.

XcodeGen/project.yml



: . project.yml



:





configs:
  Debug.Dev: debug   
  Debug.Prod: debug
  Release: release

targets:
  GoodToGo:
    type: application
    platform: iOS
    deploymentTarget: 12.0
    settings:
      base:
        MARKETING_VERSION: 1.0
    sources:
       - path: ../GoodToGo
      
      



, 3 β€” Debug.Dev, Debug.Prod Release, GoodToGo, iOS 12 ( ), GoodToGo.





, :





Spec validation error: Target β€œGoodToGo” has a missing source directory 
β€œ/Users/ricardosantos/Desktop/GitHub/RJPS_Articles/7/sourcecode/THE_FOLDER_THAT_DOES_NOT_EXISTS_NAME”
      
      



( ) …





… ( ) , !





5.

, , β€” . , , .





, , Framework.





, project.yml, , .





XcodeGen/project.yml



: :





targetTemplates:
  Framework:
    type: framework
    platform: iOS
    deploymentTarget: 11.0
    settings:
      base:
        MARKETING_VERSION: 1.0
      
      



, :





  • framework,





  • iOS,





  • 1.0,





  • , , iOS 11.0.





( ).





: AppTheme AppResources.





project.yml 2 (AppTheme AppResources). , .





 AppTheme:
    templates: 
      - Framework
    sources: 
      - path: ../AppTheme
  AppResources:
    templates: 
      - Framework
    sources: 
      - path: ../AppResources
      
      



XcodeGen/project.yml



:





( ) …





… 2 , .





: project.yml



:





targets:
  GoodToGo:
    type: application
    platform: iOS
    deploymentTarget: 12.0
    settings:
      base:
        MARKETING_VERSION: 1.0
    sources:
       - path: ../GoodToGo
  AppTheme:
    templates: 
      - Framework
    sources: 
      - path: ../AppTheme
  AppResources:
    templates: 
      - Framework
    sources: 
      - path: ../AppResources
      
      



, project.yml



:





name: GoodToGo

## options section ##

options:
  bundleIdPrefix: com.GoodToGo
  xcodeVersion: '12.0.1'
  deploymentTarget: '12.0'
  groupSortPosition: top
  generateEmptyDirectories: true
  findCarthageFrameworks: true
  minimumXcodeGenVersion: '2.18.0'

## configs section ##

configs:
  Debug.Dev: debug
  Debug.Prod: debug
  Release: release

## targetTemplates section ##

targetTemplates:
  Framework:
    type: framework
    platform: iOS
    deploymentTarget: 11.0
    settings:
      base:
        MARKETING_VERSION: 1.0

## targets section ##
        
targets:
  GoodToGo:
    type: application
    platform: iOS
    deploymentTarget: 11.0
    settings:
      base:
        MARKETING_VERSION: 1.0
    sources:
       - path: ../GoodToGo
  AppTheme:
    templates: 
      - Framework
    sources: 
      - path: ../AppTheme
  AppResources:
    templates: 
      - Framework
    sources: 
      - path: ../AppResources
  AppConstants:
    templates: 
      - Framework
    sources: 
      - path: ../AppConstants
  Core:
    templates: 
      - Framework
    sources: 
      - path: ../Core
  Core.GalleryApp:
    templates: 
      - Framework
    sources: 
      - path: ../Core.GalleryApp
  Domain:
    templates: 
      - Framework
    sources: 
      - path: ../Domain
  Core.GalleryApp:
    templates: 
      - Framework
    sources: 
      - path: ../Core.GalleryApp
  Designables:
    templates: 
      - Framework
    sources: 
      - path: ../Designables    
  DevTools:
    templates: 
      - Framework
    sources: 
      - path: ../DevTools   
  Extensions:
    templates: 
      - Framework
    sources: 
      - path: ../Extensions   
  Factory:
    templates: 
      - Framework
    sources: 
      - path: ../Factory   
  PointFreeFunctions:
    templates: 
      - Framework
    sources: 
      - path: ../PointFreeFunctions   
  Repositories:
    templates: 
      - Framework
    sources: 
      - path: ../Repositories    
  Repositories.WebAPI:
    templates: 
      - Framework
    sources: 
      - path: ../Repositories.WebAPI         
  UIBase:
    templates: 
      - Framework
    sources: 
      - path: ../UIBase  

  Test.GoodToGo:
    type: bundle.unit-test
    platform: iOS
    sources:
       - path: ../Test.GoodToGo
    scheme: {}
      
      



XcodeGen/project.yml



: ()





https://seattle.eater.com/2019/7/2/20679237/july-4th-seattle-where-to-eat-drink-and-watch-the-fireworks
https://seattle.eater.com/2019/7/2/20679237/july-4th-seattle-where-to-eat-drink-and-watch-the-fireworks

XcodeGen !

, . β€” .plist



. 2- : project.yml



.plist



, GoodToGo-info.plist Info.plist.





6.

, . .





, , Domain RxCocoa RxSwift, carthage.





-, Domain project.yml



…

XcodeGen/project.yml



: Domain :





  Domain:
    templates: 
      - Framework
    sources: 
      - path: ../Domain
      
      



… (carthage) . !

XcodeGen / project.yml



: Domain :





Domain:
    templates: 
      - Framework
    sources: 
      - path: ../Domain
    dependencies:
      - carthage: RxSwift
      - carthage: RxCocoa
      
      



, 3:





  • carthage-,





  • (link: true),





  • (link: false).





    XcodeGen/project.yml



    : (carthage, ):





 dependencies:
      - carthage: RxSwift
      - carthage: RxCocoa
      - target: BaseUI
        link: false
      - target: DevTools
        link: true
      - target: UICarTrack
        link: false
      
      



.





, ! Β« Β» β€” , , , , .. :





  • 1. .xcodeproject



    ,





  • 2. ,





  • 3. project.yml



    ,





  • 4. 1.





7. :

( ):





, postCompileScript



.





GoodToGo:
    type: application
    platform: iOS
    deploymentTarget: 12.0
    settings:
      base:
        MARKETING_VERSION: 1.0
    sources:
       - path: ../GoodToGo
    dependencies:
       ...
    postCompileScripts:
      - script: |
                if which swiftlint >/dev/null; then
                   swiftlint
                else
                   echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
                fi
        name: Run SwiftLint
      
      



8. : Documents

Documents. , , . fileGroups ( fileGroups ).





fileGroups:
  - ../Documents
      
      



IV -

  • project.yml



    XcodeGen, ( )





  • ( )









  • ( )





  • ( )









1. , :

. / Remove Reference . , XcodeGen (, ). , Documents.





2. , :

. , , , , . , Documents.





V -

  • XcodeGen .





  • .





  • .





  •   project.yml .





  • .






"iOS Developer. Professional".



Β« SwiftUI CombineΒ».








All Articles