Playground import - No such module after updating to Xcode 12 - swift-playground

I use playgrounds in a framework project. Sometimes, there were build issues, which always disappeared after building the library.
After updating to Xcode 12, I cannot run the playgrounds anymore.
import UIKit
import PlaygroundSupport
import MyFramework
// Error: No such module `MyFramework`

Select the playground. In the Playground Settings check the Build Active Scheme checkbox.
Note: In Xcode 12.0 you need to change something in the playground code, in order to really trigger the change and see it in Git.

Related

Xcode can't generate previews with Swift Package

I'm getting this error because of a Swift package I have added to my project.
HumanReadableSwiftError
SettingsError: noExecutablePath(<IDESwiftPackageStaticLibraryProductBuildable:ObjectIdentifier(0x000060001598bf60):'PersonaInquirySDK2'>)
This is the package.
https://github.com/persona-id/inquiry-ios-2.git
Is this something I can fix, or help Xcode ignore for previews?

Android Studio duplicates randomly import lines after hot reload

Is this an official bug or am I doing something wrong?
I'm using Android 3.5.3 and every time I run my Flutter project, some of my import lines are randomly being duplicated or even at times even triplicated.
You can set Android Studio to auto import files.
So my bet is to disable this function or set it to Ask in
File -> Settings -> Editor -> Auto Import -> Java and Dart

Playground Import: No Such Module 'Foo'

I've diligently followed the Apple instructions to import a custom module into a playground, including the instructions here. And yet I get:
Playground execution failed: /var/folders/z3/kd0nj4ln1rgcpm8bdz7067wh0000gs/T/./lldb/1874/playground1.swift:7:8: error: no such module 'Foo'
import Foo
How can I recover to a working Playground import? [Edit: Note, two answers have produced detailed instructions to associate a playground with a framework; I have followed those instructions but no luck. The solution will need to involve reconfiguring something in Xcode; my installation is apparently broken]
Detailed images of the error and attempts:
Here is another attempt, based on the answer of #EricD, showing the directory structure, no dice.
For some of those that none of the above solutions work (and that Xcode build path setting was already set to Unique), I've found a solution.
The framework must be built with a scheme for an iOS simulator device (any in the list) and NOT a Generic iOS Device, as Playgrounds do not support it. This one worked for me :
Here's how I proceed for OS X with Xcode 7.1:
Create new project: OS X Cocoa Framework, Swift. For this example I named it "TestPlaygroundFMK".
Create a new Swift file.
Add a class to the file. The code has to be public. I made this for our example:
import Foundation
public class Talk {
public class func sayHello() {
print("Hello from framework!")
}
}
Build the project now.
In the menu bar, click on File > Save As Workspace.
Create a new Playground and save it inside the project folder next to the Swift files.
The Playground must not have the same name as the project.
Build the project again.
Import your framework in the Playground and use it:
import TestPlaygroundFMK
Talk.sayHello()
I had my playground working fine but found that when I quit Xcode and re-opened it, I would get an error like this:
error:
/var/folders/ft/bmk8wh6s5ms4my2pxhn3qbp40000gn/T/playground1-9216e0..swift:3:8:
error: no such module 'Playground_Sources' import Playground_Sources
... where "Playground" is the name of my playground file.
The solution to this (in Xcode 9.0) is to:
click any playground file in your workspace
show the Utilities panel (opt-cmd-0)
under "Playground Settings" change the "Platform" to anything else then set it back.
In my case, it's set to macOS. I changed it to iOS then back to macOS (no recompilation necessary) and it started to work fine... that is until I close Xcode and open it again.
This is the only solution I found to work with macOS playgrounds. This bug still exists in Xcode 9.3.
I'm not sure i had the exact problem as the original question - but given the mix and age of solutions and the lack of this one that DID work for me, i thought I'd share.
In Xcode 11+ (tested this on 12.2), i'd often have Playgrounds fail to run givn the "No Such Module" error when it included a framework that is a part of the workspace.
The solution for me was in the "File Inspector" for the Playground, and the "Build Active Scheme" option:
This ensures the project was being built appropriately for the target, and now my annoying compile issues are gone!
Create a workspace as below:
Choose File > New > Workspace
Enter the workspace name, and specify its location in your file system
Click Save
Now, Create a Cocoa framework with swift file which have your class
Choose File > New > Project
Select Cocoa framework > Next
Enter Product Name and Language > Next
Before clicking create, in 'Add to:' and 'Group' list choose 'Your workspace name' as shown
Framework is added to your workspace
Create swift file in your framework
In Xcode right click on the folder where you want to add swift file and select new file...
Select swift > Next > Name your file > Create
Select your framework in Xcode -> Build your framework
Create playground -> Playground should also be part of your workspace, if not drag it to your workspace, it'll be added automatically.
Right click in Xcode's files section > New file... > Playground
import
Call your method
Note: If you just wanted to add classes instead of framework to your playground check the link How to import my own class into an Xcode 7 playground?
Solution that worked for me:
Setup your workspace and project/framework.
Delete derived data (How to remove derived data?)
DO NOT BUILD YOUR PROJECT YET
Create playground file with different name then your project/target/framework name under folder with either Swift files or where .xcodeproj is located (does not matter which one you chose)
Build your project under required platform (if playground is for macOS, then build project with macOS target, etc.)
When build finishes try adding some code to your playground and run it.
P.S. you might need to restart Xcode before 6th step.
The solution, from Apple Support, was to adjust my Xcode Preferences. On Locations :: Advanced my configuration was 'Legacy'. By changing to 'Unique', and undoing any paths I'd attempted to insert, Playgrounds can now import frameworks.
I don't think it's a stretch to say that Xcode is somewhat of a blackbox. I make no claim that this will work for anyone else, but for me, after having the same issue after creating a new playground and a new framework target, and all the other proposed solutions, what finally worked was deleting the workspace file and (in my case) regenerating it with cocoapods.
I have no idea why this worked.
Build the framework with release ,this worked for me. (Xcode 10.1, swift 4.2)
Insert a var at the first line and re run
var str = ""

Xcode can't find GPUImageHistogramEqualizationFilter, but can find other filters

I'm having a problem where Xcode is unable to find GPUImageHistogramEqualizationFilter, though it is able to find other filters without trouble. I got GPUImage going by dragging GPUImage.xcodeproj and the Resources folder into my project, and adding GPUImage.framework to the Embedded Binaries of my target. Here's a minimal example showing the error:
import UIKit
import GPUImage
class ViewController: UIViewController {
let filter1 = GPUImageBrightnessFilter() // No sweat
let filter2 = GPUImageHistogramEqualizationFilter() // No dice
}
I get the following error when instantiating filter2:
Use of unresolved identifier 'GPUImageHistogramEqualizationFilter`
I checked GPUImage.xcodeproj -> GPUImage -> GPUImage.h, and both GPUImageHistogramEqualizationFilter.h and its superclass GPUImageFilterGroup.h have been imported. I also checked the FilterShowcaseSwift example app to see if I could find a hint there, but it seems to have been left out (at least, it's not part of the enum in FilterOperations.swift).
I'm using Xcode Version 7.0 beta (7A121l), and I got whichever version of GPUImage was on GitHub yesterday.
Update:
I found that GPUImage.xcodeproj -> Targets -> GPUImageFramework -> Build Phases didn't have GPUImageHistogramEqualizationFilter.h listed under Headers, and didn't have GPUImageHistogramEqualizationFilter.m listed under Compile Sources. Unfortunately, after I added them, I get a new warning in addition to the old error:
Umbrella Header for module 'GPUImage' does not include header 'GPUImageHistogramEqualizationFilter.h'
This error persists after cleaning, closing Xcode, and deleting derived data.
Whenever I start playing with Build Phases, I always feel a bit like this guy.
Go to your project -> Build settings -> change Enable Modules (C and Objective-C) to No
The warning should go away.

Swift debugger does not show variable values when importing ObjC framework

When I create a new OS X "Game" project with Sprite Kit, and set a breakpoint anywhere I can see the variable values just fine:
Then I change the code to import my own framework (TilemapKit) which is a pure Objective-C framework:
import SpriteKit
import TilemapKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
print("dang!")
}
}
No other changes made. I'm not even using any of the TilemapKit code (yet). When the breakpoint triggers, I see this:
The entire project stops being debuggable as far as observing variable values goes. This behavior is perfectly consistent. Without the framework import I can debug again.
Since I'm on Xcode 7 beta (7A121l) and OS X 10.11 developer preview I know this could simply be a (temporary) bug.
Command line Tiles are set to use the Xcode 7.0 version btw. I tried enabling modules in the framework target, made sure the deployment target is the same (10.11), disabled symbol stripping. I added a Bridging Header and #imported the TilemapKit framework in it (removing the Swift import in that case would still give me the non-debuggable app, so it doesn't seem to matter how or where I import the framework).
Does anyone have a suggestion on what could cause this behavior and how I might go about fixing it - or at least how I could try to narrow down the issue?
Is the culprit more likely to be connected to the project's vs the framework's build settings? Do I need to enable something in the app project to make it compatible with ObjC frameworks? (I already got -ObjC in the Other Linker flags)
UPDATE:
I ran po self in the debug console and found this notice:
<built-in>:3:6: error: module 'TilemapKit' was built in directory '/TilemapKit.framework' but now resides in directory './TilemapKit.framework'
#define __clang_major__ 7
^
missing required module 'TilemapKit'
Debug info from this module will be unavailable in the debugger.
How come the framework build directory changed? And why would that matter and how to fix this?
PS: the same framework in a new ObjC app can be debugged just fine.
I got a message from an Apple developer stating that they've observed this problem, and that it could be fixed by moving the .framework to a subfolder of the project.
Apparently the module .. was built in directory error appears only if the .framework is in the same folder as the .xcodeproj aka $(PROJECT_DIR).
However moving the framework to a subfolder didn't fix the issue in my case, but it's still worth a try until this gets fixed in a newer Xcode 7 beta (still occurs in beta 3).
In my case this was happening because of redundant import statements in my project.
My project mixes swift and objc files, so I have import statements in the bridging_header.h file.
In my bridging_header.h I had #import blah.h
In one of the swift files, I was importing a redundant header from a framework
#import blah // From blah.framework
I removed the redundant import from the swift file, that seems to have fixed it.
I can confirm this is happening in Xcode Version 7.0 beta 4 (7A165t). I had to remove my ObjC framework to get Debugging values to return. If removing your framework isn't an option, the print method is old-school debugging, but still works.
I had this issue a while ago. In my case the Prefix.pch was beeing included inside the Bridging-Header.h. This is not a issue per so, but inside my Prefix.pch there was many C includes that make the lldb fail to import the Bridging-Header.
So I removed the "#import Prefix.pch" from the Bridging-Header and copied just the "#includes" to the obj-c files that I need to use in swift.
The Optimization level is not set to None for the Debug configuration.
Be sure to set it to None for Objective-C apps as shown in Figure 1 and for Swift apps as shown in Figure 2.
The Build Configuration pop-up menu is set to Release in the scheme editor's Run action settings pane.
In Xcode, open the scheme editor by choosing Product > Scheme > Edit Schemeā€¦, select the Run action for your app in the scheme actions pane, then set Build Configuration to Debug as seen in Figure 3.
Go to Edit Scheme on left top corner.
And change the configurations to Debug, if it is release

Resources