@@ -201,22 +201,56 @@ Text marked as `{}` will vary.
201
201
202
202
## Converting the Swift App to a Framework
203
203
204
- Create a new Cocoa Framework target in the Xcode project
205
- named SwiftAppLibrary, then change the Target Membership of
206
- ` AppDelegate.swift ` and ` MainMenu.xib ` to only SwiftAppLibrary
207
- in Xcode's File Inspector in the right sidebar:
204
+ Create a new Cocoa Framework target in the Xcode project,
205
+
206
+ ![ Select the Cocoa Framework template] ( tutorial/xcode-cocoa-framework-template-icon.png )
207
+
208
+ with Swift as the default language.
209
+
210
+ ![ Select Swift as the default language] ( tutorial/xcode-create-project-language-swift.png )
211
+
212
+ Name the framework SwiftAppLibrary.
213
+
214
+ ### Framework Configuration
215
+
216
+ To move over our application code and UI, change the Target
217
+ Membership of ` AppDelegate.swift ` and ` MainMenu.xib ` in Xcode's
218
+ File Inspector in the right sidebar so that they are only
219
+ included in SwiftAppLibrary:
208
220
209
221
![ Target Membership] ( tutorial/xcode-target-membership.png )
210
222
211
- In the new framework's build settings, set ** Always Embed Swift
212
- Standard Libraries** to ** Yes** .
223
+ Xcode will place the built framework in a temporary directory
224
+ (` ~/Library/Developer/Xcode/DerivedData/ ` ) with an unpredictable
225
+ subpath. So that Cabal will be able to find the framework for
226
+ linking, add a new ** Run Script** build phase to create a
227
+ symlink to the built framework in ` build/ ` :
228
+
229
+ ``` sh
230
+ set -u
231
+ ln -sf " ${BUILT_PRODUCTS_DIR} /${FULL_PRODUCT_NAME} " " ${PROJECT_DIR} /build/"
232
+ ```
233
+
234
+ ### App Bundle Configuration
213
235
214
236
Drag the ` SwiftHaskell ` executable we built previously with
215
237
Stack into Xcode from the ` build/ ` directory that we symlinked
216
238
it into, but do not add it to any targets when prompted:
217
239
218
240
![ The SwiftHaskell executable in Xcode] ( tutorial/xcode-files-swifthaskell-executable.png )
219
241
242
+ When Xcode creates Swift frameworks, it expects that the
243
+ application that links the framework will include the Swift
244
+ standard libraries. Xcode automatically adds these libraries to
245
+ Swift applications. Since our application executable is built
246
+ with Haskell and not Swift, we'll need to explicitly tell Xcode
247
+ to include the Swift standard libraries in our application.
248
+
249
+ In the app target's Build Settings tab, set ** Always Embed Swift
250
+ Standard Libraries** to ** Yes** :
251
+
252
+ ![ Always Embed Swift Standard Libraries: Yes] ( tutorial/xcode-embed-swift-standard-libs.png )
253
+
220
254
In the SwiftHaskell app target's Build Phases, remove the
221
255
** Compile Sources** and ** Link Binary With Libraries**
222
256
phases, and add a new ** Copy Files** phase that copies the
@@ -227,14 +261,6 @@ directory:
227
261
228
262
![ Copy into Executables] ( tutorial/xcode-copy-files-swifthaskell-executable.png )
229
263
230
- Finally, in the SwiftAppLibrary framework target's Build Phases,
231
- add a new ** Run Script** phase to create a symlink to the built
232
- framework for us to link to from Cabal:
233
-
234
- ``` sh
235
- set -u
236
- ln -sf " ${BUILT_PRODUCTS_DIR} /${FULL_PRODUCT_NAME} " " ${PROJECT_DIR} /build/"
237
- ```
238
264
239
265
Build the SwiftAppLibrary framework in Xcode to prepare for the
240
266
next sections.
0 commit comments