i have a swift project with some frameworks added via carthage. Is it possible to use those frameworks in playground inside project and how to use it, because
import Argo
doesn't work :(
In the app, select the project from the project navigator, select the Stocktance target, and scroll to Frameworks, Libraries, and Embedded Content. Click on the plus button, click Add Other… and select Add Files… Navigate to the SettingsKit folder and select it. We've added the framework to the project.
This stopped working at some point. Sigh
What I do now is
github "ReactiveX/RxSwift"
and run carthage update --platform iOS
At this point I’m able to run the playground files.
🤷🏻♂️
A playground has access to external frameworks if it is part of a workspace that builds a target configured to access those frameworks.
If you want to add a playground to an existing carthage project, you only need to save the project as a workspace (File > Save as Workspace…), build the target, and you are done.
If you just want to distribute a playground with third party frameworks, you need to create a dummy workspace. Here is a step by step example for a playground with the RxSwift framework:
Create a new Xcode project of type Cross-platform > Other > Empty. Name it RxPlayground.
This will create this structure RxPlayground/RxPlayground.xcodeproj and open a blank Xcode.
Download RxSwift with Carthage
github "ReactiveX/RxSwift" "swift4.0"
carthage update --platform iOS
. Add a playground to the project.
Create a workspace
Copy the frameworks to the products directory.
cp -rv "${SRCROOT}/Carthage/Build/iOS/" "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}"
At this point, Xcode and the Finder look like this:
Note that Carthage/ and Cartfile.resolved appear when you run Carthage, Without them, your playground will be only a few Ks.
Lastly, build the project (⌘B). Now you can use the framework in your playground:
//: Playground - noun: a place where people can play
import RxSwift
_ = Observable<Void>.empty()
.subscribe(onCompleted: {
print("Completed")
})
Sometimes the first time you build (⌘B) Xcode doesn’t notice the new framework (sigh). What I do is click on the target and back to a source file, or re-open the project. I don’t have an explanation why this happens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With