You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Documentation/Examples.md
+39Lines changed: 39 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -256,3 +256,42 @@ class RecentsController: UICollectionViewController {
256
256
}
257
257
}
258
258
```
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)
Copy file name to clipboardExpand all lines: Documentation/QandA.md
+2-9Lines changed: 2 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@
4
4
5
5
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).
6
6
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.
8
8
9
9
## Why should I choose R.swift over alternative X or Y?
10
10
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:
12
12
- R.swift inspects your Xcodeproj file for resources instead of scanning folders or asking you for files
13
13
- R.swift supports a lot of different assets
14
14
- 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
17
17
18
18
R.swift works with Xcode 10 for apps targetting iOS 8 and tvOS 9 and higher.
19
19
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
-
26
20
## How do I fix missing imports in the generated file?
27
21
28
22
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
45
39
- Every time you build R.swift will run
46
40
- It takes a look at your Xcode project file and inspects all resources linked with the target currently build
47
41
- It generates a `R.generated.swift` file that contains a struct with types references to all of your resources
Runtime validation with [`R.validate()`](Documentation/Examples.md#runtime-validation):
67
70
- If all images used in storyboards and nibs are available
@@ -74,7 +77,6 @@ Runtime validation with [`R.validate()`](Documentation/Examples.md#runtime-valid
74
77
-[Why was R.swift created?](Documentation/QandA.md#why-was-rswift-created)
75
78
-[Why should I choose R.swift over alternative X or Y?](Documentation/QandA.md#why-should-i-choose-rswift-over-alternative-x-or-y)
76
79
-[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)
78
80
-[How to fix missing imports in the generated file?](Documentation/QandA.md#how-to-fix-missing-imports-in-the-generated-file)
79
81
-[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)
80
82
-[Can I ignore resources?](Documentation/Ignoring.md)
@@ -89,19 +91,24 @@ As of Rswift 7, Swift Package Manager is the recommended method of installation.
89
91
90
92
[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).
91
93
92
-
### Xcode project - SPM
94
+
### Xcode project using SPM (Recommended)
93
95
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)
98
97
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.
100
102
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.
102
104
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:
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.
105
112
106
113
### Package.swift based SPM project
107
114
@@ -139,36 +146,6 @@ _Screenshot of the Build Phase can be found [here](Documentation/Images/BuildPha
139
146
_Tip:_ Add the `*.generated.swift`pattern to your `.gitignore`file to prevent unnecessary conflicts.
140
147
</details>
141
148
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
-
172
149
<details>
173
150
<summary><h3>Manually</h3></summary>
174
151
@@ -188,13 +165,10 @@ _Screenshot of the Build Phase can be found [here](Documentation/Images/ManualBu
188
165
_Tip:_ Add the `*.generated.swift`pattern to your `.gitignore`file to prevent unnecessary conflicts.
189
166
</details>
190
167
191
-
192
168
## Contribute
193
169
194
170
We'll love contributions, read the [contribute docs](Documentation/Contribute.md) for info on how to report issues, submit ideas and submit pull requests!
195
171
196
172
## License
197
173
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