Snapkit: Unable to use SnapKit inside Swift Playground

Created on 1 Sep 2017  路  10Comments  路  Source: SnapKit/SnapKit

  • [x ] I have looked at the Documentation
  • [x ] I have read the F.A.Q.
  • [x ] I have filled out this issue template.

Issue Info

Info | Value |
-------------------------|-------------------------------------|
Platform | ios
Platform Version | 10
SnapKit Version | 3.2.0
Integration Method | cocoapods

Issue Description

1) I created a simple single-view project called QuickViewBuilder (just a name ..doesn't really matter, but it suggests what I want to acchive - it is to build views, view controllers faster..using swift playgrounds..)
2) I promoted the project to workspace using Cocoapods, having SnapKit as a pod.
3) I created a Playground right inside the QuickViewBuilder project.
4) I build the project .(not ran, just built so that the SnapKit dependency is prebuilt)
5) I created a viewController inside the playground using the playground template in Xcode9. But really all there is to it is this line
PlaygroundPage.current.liveView = MyViewController()
so you can actually visualize your playground code on the right pane as if it was an app.
6) I imported SnapKit using "import SnapKit" into playground.
7) For now, no SnapKit code used in the controller, only the import declaration and the playground runs properly.
7) But - as soon as I use a single line of code trying to use snakpit to lay out subviews, i end up with this.
8) Screnshots attached to prove there is no other issue in this whole setup.
9) I can build and render the viewcontroller easily as long as I do not use SnapKit code.
10) If I do, I end up with this error message:

Playground execution failed:

error: Couldn't lookup symbols:
__T07SnapKit17ConstraintViewDSLVN
__T07SnapKit23ConstraintMakerEditableCMa
__T07SnapKit17ConstraintViewDSLV15makeConstraintsyyAA0C5MakerCcF
__T0So6UIViewC7SnapKitE3snpAC17ConstraintViewDSLVfg

Can you tell me why and what is the fix please?

nosnapkitworks
snapkitnotworking

need info

Most helpful comment

please ...

All 10 comments

That's pretty weird, I've never tried to use SnapKit in a playground but it sounds like the build system isn't loading the .framework quite right.

What version of Xcode are you using?

  1. I created a viewController inside the playground using the playground template in Xcode9.

Any update?

Bumping this up a bit ..Fixing this would be a VERY important step towards a much faster iteration cycle for very big projects...

please ...

@Krisiacik 2018-01-20 11 52 54
SnapKit (4.0.0)
Try to "pod repo udpate". Adding playground to existing workspace works in my case.

@Krisiacik ever resolved this? getting same issue with snapkit 4.0.0

Hey @Krisiacik

it depends on which version of CocoaPods you are using, cocoa pods 1.5.0 has issues with playgrounds (https://github.com/CocoaPods/CocoaPods/issues/7689)

and depending the set up of your project, you may need the workarounds mentioned in https://github.com/CocoaPods/CocoaPods/issues/5334

the main thing is: CocoaPods doesn't support playgrounds

But it's possible to use them with this workaround in your podfile:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['CONFIGURATION_BUILD_DIR'] = '$PODS_CONFIGURATION_BUILD_DIR'
    end
  end
end

But mainly: for a framework to be able to be imported in playgrounds, you need to make sure the framework is on the first level of your build products folder, which path looks a bit like this:

/Users/random/Library/Developer/Xcode/DerivedData/MyProject-crqqclflsbxmxsbyfbugjehqqxby/Build/Products/Debug-iphonesimulator

a bit of a plug, i have some relevant info of working with playgrounds in here https://github.com/fespinoza/Talks/blob/master/2018-05-23-playground-driven-development/Playground%20Driven%20Development%20-%20iOS%20Jam.pdf


It's not an issue of SnapKit

I had the same issue with playgrounds, so I resolved it in another way. I'm using the combination of Xcode/SwiftUI live previews and UIViewRepresentable protocols to test my UIKit/Snapkit code with live preview enabled. Check it here.

I had the same issue with playgrounds, so I resolved it in another way. I'm using the combination of Xcode/SwiftUI live previews and UIViewRepresentable protocols to test my UIKit/Snapkit code with live preview enabled. Check it here.

Maybe you can try my pr #669 to check if it works for you

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KaKuiTsang picture KaKuiTsang  路  10Comments

monowerker picture monowerker  路  11Comments

Shehryar picture Shehryar  路  7Comments

Cookiezby picture Cookiezby  路  8Comments

tcurdt picture tcurdt  路  16Comments