Skip to content

Commit cad6747

Browse files
committed
Documentation updates
1 parent 1965acc commit cad6747

File tree

4 files changed

+59
-53
lines changed

4 files changed

+59
-53
lines changed

Documentation/Examples.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,42 @@ class RecentsController: UICollectionViewController {
256256
}
257257
}
258258
```
259+
260+
## Project
261+
262+
*Vanilla*
263+
```swift
264+
let developmentRegion = fatalError("Not available at runtime")
265+
let myTag = "myTag"
266+
```
267+
268+
*With R.swift*
269+
270+
Access the development region and any asset tags that are set on the project file.
271+
272+
```swift
273+
let developmentRegion = R.project.developmentRegion
274+
let myTag = R.project.knownAssetTags.myTag
275+
```
276+
277+
## Entitlements
278+
279+
*With R.swift*
280+
281+
Access the values in the entitlement file you embedded. This might differ from the entitlements your app actually has at runtime! But it's greate to get some identifiers in a consistent way.
282+
283+
```swift
284+
let appGroupIdentifier = R.entitlements.comAppleSecurityApplicationGroups.groupMyAppGroup
285+
```
286+
287+
## Info.plist
288+
289+
Values under `UIApplicationShortcutItems`, `UIApplicationSceneManifest`, `NSUserActivityTypes`, `NSExtension` that are often needed in code are available directly through R.swift.
290+
291+
*With R.swift*
292+
293+
Access the values in the entitlement file you embedded. This might differ from the entitlements your app actually has at runtime! But it's greate to get some identifiers in a consistent way.
294+
295+
```swift
296+
let sceneConfiguration = UISceneConfiguration(name: R.info.uiApplicationSceneManifest.uiSceneConfigurations.uiWindowSceneSessionRoleApplication.defaultConfiguration.uiSceneConfigurationName, sessionRole: .windowApplication)
297+
```
2.33 MB
Binary file not shown.

Documentation/QandA.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
Swift is a beautiful language and one of it's main advantages is its increasing popularity. However, it can be frustrating to deal with errors that compile but fail during runtime due to missing resources. This makes refactoring difficult while making it easy to create bugs (e.g. missing images etc).
66

7-
Android tackles this problem by generating something called the R class. It inspired me to create this very project, R.swift, which, thankfully, was well received by colleagues, friends and Github stargazers, so here we are now.``
7+
Android tackles this problem by generating something called the R class. It inspired me to create this very project, R.swift, which, thankfully, was well received by colleagues, friends and Github stargazers, so here we are now.
88

99
## Why should I choose R.swift over alternative X or Y?
1010

11-
There are many nice R.swift alternatives like [SwiftGen](https://github.com/AliSoftware/SwiftGen), [Shark](https://github.com/kaandedeoglu/Shark) and [Natalie](https://github.com/krzyzanowskim/Natalie). However, I believe R.swift has these important advantages:
11+
There are many nice R.swift alternatives like [SwiftGen](https://github.com/AliSoftware/SwiftGen) and [Shark](https://github.com/kaandedeoglu/Shark). However, I believe R.swift has these important advantages:
1212
- R.swift inspects your Xcodeproj file for resources instead of scanning folders or asking you for files
1313
- R.swift supports a lot of different assets
1414
- R.swift stays very close to the vanilla Apple API's, having minimal code change with maximum impact
@@ -17,12 +17,6 @@ There are many nice R.swift alternatives like [SwiftGen](https://github.com/AliS
1717

1818
R.swift works with Xcode 10 for apps targetting iOS 8 and tvOS 9 and higher.
1919

20-
## How do I use methods with a `Void` argument?
21-
22-
Xcode might autocomplete a function with a `Void` argument (`R.image.settingsIcon(Void)`); to solve this, simply remove the `Void` argument and you're good to go: `R.image.settingsIcon()`.
23-
24-
The reason this happens is because of the availability of the var `R.image.settingsIcon.*` for information about the image and also having a function with named the same name.
25-
2620
## How do I fix missing imports in the generated file?
2721

2822
If you get errors like `Use of undeclared type 'SomeType'` in the `R.generated.swift` file, this can usually be fixed by [explicitly stating the module in your xib or storyboard](Images/ExplicitCustomModule.png). This will make R.swift recognize that an import is necessary.
@@ -45,4 +39,3 @@ During installation you add R.swift as a Build phase to your target, basically t
4539
- Every time you build R.swift will run
4640
- It takes a look at your Xcode project file and inspects all resources linked with the target currently build
4741
- It generates a `R.generated.swift` file that contains a struct with types references to all of your resources
48-

README.md

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ R.swift currently supports these types of resources:
6262
- [Segues](Documentation/Examples.md#segues)
6363
- [Nibs](Documentation/Examples.md#nibs)
6464
- [Reusable cells](Documentation/Examples.md#reusable-table-view-cells)
65+
- [Project](Documentation/Examples.md#project)
66+
- [Entitlements](Documentation/Examples.md#entitlements)
67+
- [Info.plist](Documentation/Examples.md#info-plist)
6568

6669
Runtime validation with [`R.validate()`](Documentation/Examples.md#runtime-validation):
6770
- If all images used in storyboards and nibs are available
@@ -74,7 +77,6 @@ Runtime validation with [`R.validate()`](Documentation/Examples.md#runtime-valid
7477
- [Why was R.swift created?](Documentation/QandA.md#why-was-rswift-created)
7578
- [Why should I choose R.swift over alternative X or Y?](Documentation/QandA.md#why-should-i-choose-rswift-over-alternative-x-or-y)
7679
- [What are the requirements to run R.swift?](Documentation/QandA.md#what-are-the-requirements-to-run-rswift)
77-
- [How to use methods with a `Void` argument?](Documentation/QandA.md#how-to-use-methods-with-a-void-argument)
7880
- [How to fix missing imports in the generated file?](Documentation/QandA.md#how-to-fix-missing-imports-in-the-generated-file)
7981
- [How to use classes with the same name as their module?](Documentation/QandA.md#how-to-use-classes-with-the-same-name-as-their-module)
8082
- [Can I ignore resources?](Documentation/Ignoring.md)
@@ -89,19 +91,24 @@ As of Rswift 7, Swift Package Manager is the recommended method of installation.
8991

9092
[Demo video: Updating from R.swift 6 to Rswift 7](https://youtu.be/icihJ_hin3I?t=66) (Starting at 1:06, this describes the installation of Rswift 7).
9193

92-
### Xcode project - SPM
94+
### Xcode project using SPM (Recommended)
9395

94-
1. In Project Settings, on the tab "Package Dependencies", click "+" and add `github.com/mac-cain13/R.swift`
95-
2. Select your target, on the tab "General", in the section "Frameworks, Libraries, and Embeded Content", click "+" and add `RswiftLibrary`
96-
3. Select your target, on the tab "Build Phases", in the section "Run Build Tool Plug-ins", click "+" and add `RswiftGenerateInternalResources`
97-
4. Build your project, now the `R` struct should be available in your code, use auto-complete to explore all static references
96+
[Demo Video: Install R.swift in Xcode with SPM](Documentation/RswiftSPMInstallation.mp4)
9897

99-
_Screenshot of the Build Phase can be found [here](Documentation/Images/RunBuildToolPluginsRswift.png)_
98+
1. In Project Settings, on the tab "Package Dependencies", click "+", search for `github.com/mac-cain13/R.swift` and click "Add Package".
99+
2. Select the target that will use R.swift next to "RswiftLibrary" and click "Add Package".
100+
4. Now click on your target, on the tab "Build Phases", in the section "Run Build Tool Plug-ins", click "+" and add `RswiftGenerateInternalResources`. ([Screenshot](Documentation/Images/RunBuildToolPluginsRswift.png))
101+
5. Now the `R` struct should be available in your code, use auto-complete to explore all static references.
100102

101-
#### When running on Xcode Cloud
103+
Note: The first build you might need to approve the new plugin by clicking the build error warning you about the new plugin.
102104

103-
5. Add a [custom build script](https://developer.apple.com/documentation/xcode/writing-custom-build-scripts) in `ci_scripts/ci_post_clone.sh` with the content:
104-
`defaults write com.apple.dt.Xcode IDESkipPackagePluginFingerprintValidatation -bool YES`
105+
#### R.swift on Xcode Cloud or any other CI
106+
107+
On your CI server you can't explicitly allow the build plugin to run, so you need to disable plugin validation to be able to build without user interaction:
108+
109+
5. Run a script on your CI that runs: `defaults write com.apple.dt.Xcode IDESkipPackagePluginFingerprintValidatation -bool YES` before Xcode starts building.
110+
111+
On Xcode Cloud you can add a [custom build script](https://developer.apple.com/documentation/xcode/writing-custom-build-scripts) in `ci_scripts/ci_post_clone.sh` with this line that Xcode will run.
105112

106113
### Package.swift based SPM project
107114

@@ -139,36 +146,6 @@ _Screenshot of the Build Phase can be found [here](Documentation/Images/BuildPha
139146
_Tip:_ Add the `*.generated.swift` pattern to your `.gitignore` file to prevent unnecessary conflicts.
140147
</details>
141148

142-
143-
<details>
144-
<summary><h3>Mint</h3></summary>
145-
146-
0. Add the [R.swift](https://github.com/mac-cain13/R.swift) library to your project
147-
1. Add `mac-cain13/R.swift` to your [Mintfile](https://github.com/yonaskolb/Mint#mintfile) and run `mint bootstrap` to install this package without linking it globally (recommended)
148-
2. In Xcode: Click on your project in the file list, choose your target under `TARGETS`, click the `Build Phases` tab and add a `New Run Script Phase` by clicking the little plus icon in the top left
149-
3. Drag the new `Run Script` phase **above** the `Compile Sources` phase, expand it and paste the following script:
150-
```bash
151-
if mint list | grep -q 'R.swift'; then
152-
mint run R.swift@v7.0.1 rswift generate "$SRCROOT/R.generated.swift"
153-
else
154-
echo "error: R.swift not installed; run 'mint bootstrap' to install"
155-
return -1
156-
fi
157-
```
158-
4. Add `$SRCROOT/R.generated.swift` to the "Output Files" of the Build Phase
159-
5. Uncheck "Based on dependency analysis" so that R.swift is run on each build
160-
6. Build your project, in Finder you will now see a `R.generated.swift` in the `$SRCROOT`-folder, drag the `R.generated.swift` files into your project and **uncheck** `Copy items if needed`
161-
162-
_Tip:_ Add the `*.generated.swift` pattern to your `.gitignore` file to prevent unnecessary conflicts.
163-
</details>
164-
165-
166-
<details>
167-
<summary><h3>Homebrew</h3></summary>
168-
169-
R.swift is also available through [Homebrew](http://brew.sh). This makes it possible to install R.swift globally on your system. Install R.swift by running: `brew install rswift`. The Homebrew formula is maintained by [@tomasharkema](https://github.com/tomasharkema).
170-
</details>
171-
172149
<details>
173150
<summary><h3>Manually</h3></summary>
174151

@@ -188,13 +165,10 @@ _Screenshot of the Build Phase can be found [here](Documentation/Images/ManualBu
188165
_Tip:_ Add the `*.generated.swift` pattern to your `.gitignore` file to prevent unnecessary conflicts.
189166
</details>
190167

191-
192168
## Contribute
193169

194170
We'll love contributions, read the [contribute docs](Documentation/Contribute.md) for info on how to report issues, submit ideas and submit pull requests!
195171

196172
## License
197173

198-
[R.swift](https://github.com/mac-cain13/R.swift) and [R.swift.Library](https://github.com/mac-cain13/R.swift.Library) are created by [Mathijs Kadijk](https://github.com/mac-cain13) and released under a [MIT License](License).
199-
200-
Special thanks to [Tom Lokhorst](https://github.com/tomlokhorst) for his major contributions and help maintaining this project.
174+
[R.swift](https://github.com/mac-cain13/R.swift) is created by [Mathijs Kadijk](https://github.com/mac-cain13) and [Tom Lokhorst](https://github.com/tomlokhorst) released under a [MIT License](License).

0 commit comments

Comments
 (0)