Skip to content

Commit

Permalink
Update for Xcode Version 12.3 (12C33), fixes #47 and #46
Browse files Browse the repository at this point in the history
  • Loading branch information
fulldecent committed Dec 24, 2020
1 parent 29aed85 commit e96f33b
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 369 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Swift 5 Module Template
Use this template as a starting point for any Swift 5 module that you want other people to include in their projects.

**STATUS: This template is ready and works in production code, compatible with Xcode 11.1 (11A1027)**
**STATUS: This template is ready and works in production code, compatible with Xcode 12.3 (12C33)**

![Swift 5 Module directory layout](https://user-images.githubusercontent.com/382183/66881876-63cca680-ef96-11e9-9dde-ae9d5c35350c.png)

Expand All @@ -16,7 +16,7 @@ Your new Swift 5 module will immediately have working, compilable code, and all
- Testing as a standard
- Turnkey access to Travis CI
- Semantic versioning and a CHANGELOG
- Included example/demo app
- Included example/demo app using SwiftUI

We make the assumption you are using an Xcode project to manage your code.

Expand Down Expand Up @@ -53,6 +53,19 @@ To skip interactive prompts in the `./configure` script, use these environment v

For example, you may use: `export SMT_ORGANIZATION_NAME='Awesome Org'` before running `./configure`.

## How it works

```
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Use │ │ Save │ │Use your own │
│ Xcode │─Save recipe─▶│ template │─./configure─▶│ module │
└─────────────┘ └─────────────┘ └─────────────┘
▲ ▲ ▲ ▲ ▲
│ │ │ │ │
Contributors to this project End users of this project
```

## Contributing

See the file [`Recipe.md`](Recipe.md) for the complete steps (e.g. Open Xcode, make new project, click here, type that, …) of how we made the template.
See the file [Recipe.md](Recipe.md) for the complete steps (e.g. Open Xcode, make new project, click here, type that, …) of how we made the template.
97 changes: 49 additions & 48 deletions Recipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

This recipe documents exactly how we created the Swift 5 Module Template. Please follow along and you should create a template that is identical to the one we provided. If this recipe is not perfect (or your result is different from our template in any way) then please submit an issue or pull request.

This recipe may also be useful for other scenarios, for example maybe you want to make a project that has the iOS example app using storyboards instead of SwiftUI.


## Ingredients

During the steps of this recipe we enter specific values where needed. These are chosen carefully so that they can be found and replaced in the template to create your project.
During the steps of this recipe we enter specific values where needed. These are chosen carefully so that the `./configure` script can later find and replace these values in the template to create your project.

Some variables have spaces in them. That is intentional because it causes Xcode to use double quotes around them in its project configuration files.

Expand Down Expand Up @@ -35,14 +37,15 @@ Some variables have spaces in them. That is intentional because it causes Xcode

Complete all these instructions on the same calendar day.

Use Xcode Version 11.1 (11A1027). *This is the latest publicly released or Gold Master version.*
Use Xcode Version 12.3 (12C33). *This is the latest publicly released or Gold Master version.*

### I. Create a package for your module

1. In Xcode, choose File > New > Swift Package…
1. Navigate to your Desktop folder
2. Type the name `xxPROJECTxNAMExx`
3. Click “Create"
3. Ensure "Create Git repository on my Mac" is unchecked
4. Click “Create"


### II. Add some functionality to the module
Expand All @@ -52,45 +55,44 @@ Use Xcode Version 11.1 (11A1027). *This is the latest publicly released or Gold
```sh
cd ~/Desktop/xxPROJECTxNAMExx/Sources/xxPROJECTxNAMExx/
curl 'https://raw.githubusercontent.com/fulldecent/swift5-module-template/master/xxPROJECTxNAMExx/Sources/xxPROJECTxNAMExx/xxPROJECTxNAMExx.swift' -o xxPROJECTxNAMExx.swift
curl 'https://raw.githubusercontent.com/fulldecent/swift5-module-template/master/xxPROJECTxNAMExx/Sources/xxPROJECTxNAMExx/White King.swift' -o White\ King.swift
curl 'https://raw.githubusercontent.com/fulldecent/swift5-module-template/master/xxPROJECTxNAMExx/Sources/xxPROJECTxNAMExx/White%20King.swift' -o White\ King.swift
```

### III. Create a Swift project for your iOS Example application

1. In Xcode, choose File > New > Project…
1. *Choose a template*
1. Click "iOS" then "Single View App"
1. Click "iOS" then "App"

2. Click "Next"

2. *Set the project options*
1. Set Product Name to "iOS Example"
2. Set Organization Name to `__ORGANIZATION NAME__`
2. Set Team to "NONE"
3. Set Organization Identifier to `com.AN.ORGANIZATION.IDENTIFIER`
4. Set Language to "Swift"
5. Set User Interface to "Storyboard"
6. Ensure "Include Unit Tests" is not selected
7. Ensure "Include UI Tests" is not selected
4. Set User Interface to "SwiftUI"
5. Set Life Cycle to "SwiftUI App"
6. Set Language to "Swift"
7. Ensure "Include Tests" is not selected
8. Click “Next"
3. *Create the project*
1. Ensure “Create Git Repository" is not selected
2. Ensure the 'add to' function is “Don’t add to any project or workspace"
3. Select the folder `xxPROJECTxNAMExx` on the desktop
1. Ensure “Create Git Repository on my Mac" is not selected
2. Ensure "Add to" is “Don’t add to any project or workspace"
3. Select the folder `xxPROJECTxNAMExx` on the desktop (don't double click it)
4. Click “Create"

### IV. Use the directory layout structure like Alamofire

1. *Move iOS Example source code to a folder named "Sources"*
1. Open the file iOS Example.xcodeproj in Xcode
2. Enable the Project navigator on the left
2. Enable the Project navigator on the left (folder icon)
3. Use the Project navigator to select the "iOS Example" folder (yellow icon)
4. From the Project navigator, rename this folder as "Sources"
* :warning: Using the File inspector to rename a folder would result in the change being reverted. This is an Xcode bug that we work around.
* :information_source: The Alamofire project uses the folder name "Source" but we choose "Sources" here to be consistent with the default of Swift Package Manager
* :information_source: The Alamofire project uses [the folder name "Source"](https://github.com/Alamofire/Alamofire/tree/master/Example/Source) but we choose "Sources" here to be consistent with [the default of Swift Package Manager](https://github.com/apple/swift-package-manager/blob/b1a6f45aa9daed0c8a609d34af8f71cf4282ddd4/Sources/Workspace/InitPackage.swift#L256)
2. *Fix the Info.plist file configuration and preview content folder (Xcode makes renaming folders a pain)*
1. Click "iOS Example" on the left (the blue icon)
2. Click the target "iOS Example" in the middle (app icon)
3. Click 'Build Settings' on the top of the middle
3. Click "Build Settings" on the top of the middle
4. Enter "/Info" in the search box
5. Edit the "Info.plist File" from "iOS Example/Info.plist" to be "Sources/Info.plist"

Expand All @@ -100,16 +102,12 @@ Use Xcode Version 11.1 (11A1027). *This is the latest publicly released or Gold

```sh
cd ~/Desktop/xxPROJECTxNAMExx/iOS\ Example/Sources
curl 'https://raw.githubusercontent.com/fulldecent/swift5-module-template/master/xxPROJECTxNAMExx/iOS Example/Sources/Base.lproj/Main.storyboard' -o Base.lproj/Main.storyboard
curl 'https://raw.githubusercontent.com/fulldecent/swift5-module-template/master/xxPROJECTxNAMExx/iOS Example/Sources/ContentView.swift' -o ContentView.swift
```

### VI. Make your iOS Example application depend on your module

1. Close everything that is open in Xcode

- ⚠️ This is a workaround an Xcode bug where adding a Swift package to a workspace, when that Swift package is open in a separate window, will improperly load the package as ".." instead of the correct package name.

2. Open iOS Example.xcodeproj in Xcode
1. Open iOS Example.xcodeproj in Xcode

3. Drag the `xxPROJECTxNAMExx` folder on your desktop into the Xcode Project navigator at the bottom, be sure it is subordinated under iOS Example
:x:: ![bad](Recipe.assets/bad.png)
Expand All @@ -121,15 +119,17 @@ Use Xcode Version 11.1 (11A1027). *This is the latest publicly released or Gold
3. Set the name as "iOS Example.xcworkspace"
4. Click Save
- ⚠️ Xcode will also show the iOS Example folder inside the `xxPROJECTxNAMExx` module. Swift packages are unable to specify excluded files. You can safely ignore that folder.

- :warning: Xcode has an error where this added dependency will show as ".." instead of the correct name. This discrepency can be safely ignored and it will show correctly the next time you open this workspace.

4. *Add a build dependency*

1. Click "iOS Example" on the left (the blue icon)
2. Click the target "iOS Example" in the middle (app icon)
3. Click 'Build Phases' on the top of the middle
3. Click "Build Phases" on the top
4. Open the section Link Binary With Libraries
5. Click the plus (+) button
6. Select xxPROJECTxNAMExx (the building icon)
6. Select `xxPROJECTxNAMExx` (the building icon)
7. Click "Add"

### VII. Add additional project management files to the module

Expand All @@ -138,7 +138,7 @@ These files represent best practices which every Swift module author should adop
1. Use Terminal.app to add additional files to the project

2. ```sh
cd ~/Desktop/xxPROJECTxNAMExx/
cd ~/Desktop/xxPROJECTxNAMExx/
curl 'https://raw.githubusercontent.com/github/gitignore/master/Swift.gitignore' -o .gitignore
curl 'https://raw.githubusercontent.com/fulldecent/swift5-module-template/master/xxPROJECTxNAMExx/.travis.yml' -o .travis.yml
curl 'https://raw.githubusercontent.com/fulldecent/swift5-module-template/master/xxPROJECTxNAMExx/LICENSE' -o LICENSE
Expand All @@ -148,19 +148,18 @@ These files represent best practices which every Swift module author should adop
echo 'xxPROJECTxNAMExx.framework.zip' >> .gitignore
curl 'https://raw.githubusercontent.com/fulldecent/swift5-module-template/master/xxPROJECTxNAMExx/Tests/CheckCocoaPodsQualityIndexes.rb' -o Tests/CheckCocoaPodsQualityIndexes.rb
```

### VIII. Remove identifying parts of your project

This step allows everybody to achieve byte-for-byte consistency with the published Swift 5 Module Template but otherwise provides no value to you.
This step allows everybody to achieve byte-for-byte consistency with [the published Swift 5 Module Template](https://github.com/fulldecent/swift5-module-template/tree/master/xxPROJECTxNAMExx) but otherwise provides no value to you.

1. Use Terminal.app to find and replace all occurrences of hard-coded strings with template variables

```sh
find -E ~/Desktop/xxPROJECTxNAMExx \
-regex '.*\.(h|swift)' -exec sed -i '' -E -e '
s-(// +Created by ).*( on ).*\.-\1__AUTHOR NAME__\2__TODAYS_DATE__.-
s-(// +Copyright © ).*-\1__TODAYS_YEAR__ __ORGANIZATION NAME__. All rights reserved.-' \
'{}' \;
-regex '.*\.(h|swift)' -exec sed -i '' -E -e '
s-(// +Created by ).*( on ).*\.-\1__AUTHOR NAME__\2__TODAYS_DATE__.-
s-(// +Copyright © ).*-\1__TODAYS_YEAR__ __ORGANIZATION NAME__. All rights reserved.-' \
'{}' \;
```

2. Use Terminal.app to remove all references to development team IDs
Expand All @@ -173,30 +172,32 @@ This step allows everybody to achieve byte-for-byte consistency with the publish

## Taste testing

1. Open `xxPROJECTxNAMExx`.xcworkspace
1. Open iOS Example.xcodeproj in Xcode

2. Use the scheme navigator to select iOS Example and the latest iPhone version

3. Choose Product > Run

* :warning: There appears to be a bug with Xcode saying "One of the paths in DEVELOPMENT_ASSET_PATHS does not exist". The workaround is to delete Development Assets from the Build Settings on the iOS Example target.
* :white_check_mark: You should see a big white king (♔). That means it worked!

4. *Compare with the distributed Swift 5 Module Template repository*
4. *Compare with the distributed Swift 5 Module Template repository*

1. Use Terminal.app to clone the repository to your desktop

1. Clone the repository to your desktop use Terminal
```sh
git clone https://github.com/fulldecent/swift5-module-template.git ~/Desktop/swift5-module-template
```

```sh
git clone https://github.com/fulldecent/swift5-module-template.git ~/Desktop/swift5-module-template
```
2. Compare the distributed version with your version

2. Compare the distributed version with your version
```sh
cd ~/Desktop/swift5-module-template
rm -rf xxPROJECTxNAMExx
cp -r ~/Desktop/xxPROJECTxNAMExx .
git diff
```

```sh
cd ~/Desktop/swift5-module-template
rm -rf xxPROJECTxNAMExx
cp -r ~/Desktop/xxPROJECTxNAMExx .
git diff
```
* :white_check_mark: You should see an empty screen (press <kbd>q</kbd> to close)
* :mega: If you see differences, please raise an issue in the project repository

* :white_check_mark: You should see an empty screen (press <kbd>q</kbd> to close)
* :mega: If you see differences, please raise an issue in the project repository

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions xxPROJECTxNAMExx/Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// swift-tools-version:5.1
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "xxPROJECTxNAMExx",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "xxPROJECTxNAMExx",
targets: ["xxPROJECTxNAMExx"]),
Expand All @@ -17,7 +17,7 @@ let package = Package(
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "xxPROJECTxNAMExx",
dependencies: []),
Expand Down
37 changes: 0 additions & 37 deletions xxPROJECTxNAMExx/iOS Example/Sources/AppDelegate.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading

0 comments on commit e96f33b

Please sign in to comment.