<iOS 工具>一些常用的工具性腳本和配置

  1. 下面的腳本用于自動將工程打包為一個二進制 Framework(用于私有 Framework 的二進制打包):

    #!/bin/sh
    carthage build --no-skip-current
    path=$(dirname $0)
    path=${path/\./$(pwd)}
    path=${path##*/}
    echo $path
    carthage archive $path
    
  2. 一個簡單的 Carthage 腳本, 用于自動下載和編譯依賴:

    #!/bin/sh
    carthage update --platform iOS --cache-builds --no-use-binaries
    
  3. 一個比較通用的 gitignore 文件:

    # Xcode
    #
    # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
    
    ## Build generated
    build/
    DerivedData/
    
    ## Various settings
    *.pbxuser
    !default.pbxuser
    *.mode1v3
    !default.mode1v3
    *.mode2v3
    !default.mode2v3
    *.perspectivev3
    !default.perspectivev3
    xcuserdata/
    
    ## Other
    *.moved-aside
    *.xcuserstate
    
    ## Obj-C/Swift specific
    *.hmap
    *.ipa
    
    # CocoaPods
    #
    # We recommend against adding the Pods directory to your .gitignore. However
    # you should judge for yourself, the pros and cons are mentioned at:
    # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
    #
    Pods/
    #Podfile.lock
    
    # Carthage
    #
    # Add this line if you want to avoid checking in source code from Carthage dependencies.
    Carthage/Checkouts
    Carthage/Build
    
    */Carthage/Checkouts
    */Carthage/Build
    # fastlane
    #
    # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 
    # screenshots whenever they are needed.
    # For more information about the recommended setup visit:
    # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md
    
    fastlane/report.xml
    fastlane/screenshots
    
    .DS_Store
    *.swp
    #.gitignore
    fastlane/README.md
    fastlane/test_output/report.html
    fastlane/test_output/report.junit
    
    *.framework.zip
    
  4. 一個適用于高度注重可維護性工程中 swiftlint 配置文件(借鑒若干資料, 并在兩個生產(chǎn)工程中實踐, 算法工程的話建議參考 Raywenderlich 網(wǎng)站的):

    disabled_rules: # rule identifiers to exclude from running
    #  - colon
    #  - comma
    #  - control_statement
    #   - for_where
    #   - force_unwrapping
    opt_in_rules: # some rules are only opt-in
      - empty_count
      - missing_docs
      - closure_end_indentation
      - closure_spacing
        #  - force_unwrapping
        #- implicitly_unwrapped_optional
      - operator_usage_whitespace
      - redundant_nil_coalescing
    
    included: # 包含目錄`--path` is ignored if present.
      - ./
    
    excluded: # 排除目錄, 這個是在包含目錄之前進行排除的
      - Carthage
      - Pods
      - Demo
    
    force_cast: warning # implicitly
    force_try:
      severity: warning # explicitly
    
    # 行寬
    line_length: 120
    
    # 類型體的長度
    type_body_length: 
      - 300 # warning
      - 400 # error
    
    # 方法或函數(shù)體的長度
    function_body_length: 15
    
    # 方法或函數(shù)的參數(shù)個數(shù)限制
    function_parameter_count: 4
    
    # 文件的長度限制
    file_length:
      warning: 500
      error: 600
    
    # 代碼單元結點分支個數(shù)
    cyclomatic_complexity:
      warning: 5
      error: 10
    
    # 類型名稱的長度規(guī)定
    type_name:
      min_length: 2 # only warning
      max_length: # warning and error
        warning: 40
        error: 50
      excluded: iPhone # excluded via string
    
    # 標識符長度規(guī)定 
    identifier_name:
      min_length: # only min_length
        error: 2 # only error
      excluded: # excluded via string array
        - T
    
    reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji)
    
  5. 在 Xcode 工程中配置 Carthage:

    1. 新建一個 Run Script, 添加內容:

      /usr/local/bin/carthage copy-frameworks
      

      另外如果想要在比如 debug 模式下才復制的話(比如使用 FLEX 的時候), 可以這樣:

      if [ "$CONFIGURATION" == "Debug" ]; then
        /usr/local/bin/carthage copy-frameworks
      fi
      
    2. 在其中的 input file 里面添加諸如下面的內容:

      $(SRCROOT)/Carthage/Build/iOS/Alamofire.framework
      
    3. 同時對應在 output file 中添加如下類似如下內容:

      $(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Alamofire.framework
      
  6. 配置 Swiftlint 的簡單流程:

    1. 首先將需要的 .swiftlint.yml配置文件寫好, 放到想要進行語法檢查的目錄或根目錄.

    2. 新建一個 Run Script, 添加內容:

      swiftlint
      swiftlint autocorrect
      
    3. 如果要打開或關閉某個語法檢查功能:

      // swiftlint:disable function_body_length
      // swiftlint:enable function_body_length
      
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容