I am trying to use Apple's Swift Charts (iOS 16 only) but it can't compile, I presume because the import statement is interpreted as targeting this library: https://github.com/danielgindi/Charts (that I am using in other places in the App and installed via Cocoapods) and not Apple's Swift Charts as I want to.
Using Swift Chart's API results in compile error: "Can not find 'Chart' in scope"
Any fix, workaround or better way to specify better what to import is welcomed, haven't found any other solution than nuking this library from my project, however I would need it for users with iOS 15 or less.
I seem to be unable to use Swift Charts because of this library
When I build my simple menubar cocoa application written in Swift 4 with Xcode 9, a lot of libswift*.dylib libraries are linked/downloaded/embedded into .app bundle,into Frameworks folder as seen below:
I am only using import Cocoa and import Foundation in my project, and some #objc functions as selector to timer functions. I really don't think my very simple menubar app would need some 3D rendering Metal library functions or any SwiftOnoneSupport, so I would like them to be removed from the .app bundle. (Same libraries are also included in the helper app for launch at login feature, which makes even the helper app over 10 MB)
I would have thought Xcode would just copy whatever is neccessary by default actually. Some similar questions were asked here and here but I don't think there is a fulfilling and up-to-date answer to both.
What I have tried so far
I set ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to NO in Build Settings. It doesn't seem to have any effect.
I set LINK_WITH_STANDARD_LIBRARIES to NO in Build Settings. It ruined everything and couldn't make it build even though I tried to add some frameworks(Cocoa, Foundation) on my own under Linked Frameworks and Libraries section.
Simply put, it's not possible to exclude the standard libraries that Swift automatically includes with an app and expect it to work. Currently any application created with Swift bundles its own version of the Swift Dynamic Library. Swift doesn’t live on the OS, rather it lives within each app bundle. What this means is that any app that is using Swift 4.1 for example bundles in the Swift 4.1 Dynamic Library (containing the 4.1 ABI), and so forth.
One of the things on the Swift project roadmap is to eventually have ABI Stability. If Swift becomes ABI Stable, Swift will live within the OS and it’s ABI will be compatible with every version of Swift.
From iOS v12.2 ABI[About] Stability for iOS is on. That is why your target will not include Swift standard library[About] because it is a part of OS
Alternative titles (to aid searching)
Cannot debug Swift 2.3 framework linked to an Objective-C app in Xcode 8
error in auto-import: failed to get module 'XYZ' from AST context Xcode 8
Xcode 8 cannot debug Swift framework
warning: Swift error in module <XYZ>
Workaround for; Xcode Debugger cannot debug apps written in Objective-C only but that link against frameworks written in Swift only. (28312362)
I have an app written in Objective-C that links against some modules (frameworks) written in Swift 2.x.
Question
Everything (debugging etc.) works fine in xcode7, however when moving to xcode8 and updating the modules to use swift2.3 I was unable to debug the modules.
LLDB reported these errors:
warning: Swift error in module XYZ.
Debug info from this module will be unavailable in the debugger.
error: in auto-import:
failed to get module 'ABC' from AST context
This does not happen if I link the modules to an app built in Swift 2.3.
For me it was just as simple as it was painful and time consuming:
import SDWebImage was the PROBLEM,
because one of the frameworks had the SDWebImage already packed in it(and I couldn't see it), and that framework happened to be Objective-C, and the app was Swift.
I also added the SDWebImage to the project, because I use it in the classes I write, and that what created the mess the Xcode debugger couldn't deal with.
So basically, make sure you don't have ANYTHING duplicated in ANY way, I'd check for common things like SDWebImage for example.
use fr v instead po for debugging
For more debugging
https://www.codeproject.com/Articles/1181358/Debugging-with-Xcode
I discussed this issue with an Apple engineer named Sean at WWDC 2017.
My team spent weeks trying to figure this out, and it ended up being a bug on Apple's compiler, which we could never have figured out by ourselves. Also, it has a VERY easy workaround.
There happens to be a bug with the way the compiling flags get aggregated from the frameworks and the project, and the "pure Objective-C" project "activates" it.
Solution: add one single, empty Swift file ("Whatever.swift", or whatever) in your Objective-C project, making it not-pure-objective-c anymore (new->file->Swift file, don't create the bridging header. The file will only contain the import of Foundation).
And that's it. Problem solved.
tl:dr
Add a user defined setting under "Build Settings" for your app target.
SWIFT_VERSION = 2.3
More Info
I'm unsure if this is an Xcode 8 bug or if it's Apple policy (to try an force developers to Swift 3.0?). But... by default Xcode 8 installs the Swift 3.0 versions of the standard Swift runtime libraries.
When it comes to debugging with LLDM the Swift 2.3 modules fail to load (in to the Swift 3.0 runtime).
Forcing the app to use Swift 2.3 (or legacy Swift as Apple call it), fixes the issue.
Swift apps have this setting exposed by Xcode but you have to manually add it for an Objective-C app.
Further Advice
Port your Swift 2.3 code to Swift 3.0 as soon as possible, Apple won't support 2.x for very long.
In my case, I had to remove Objective-C Bridging header from build settings file. My Bridging header file did not do anything.. so it was okay.
I ran into the error in auto-import: failed to get module 'XYZ' from AST context message while attempting to debug in an 9.3 simulator. Switching to a 10.2 simulator resolved the issue.
I ran into this when building a framework with Carthage. Trying to debug would print the error, which referenced an Obj-C framework dependency.
I found this blog post which suggested adding a the following user-defined build setting to my project:
For Debug: REMOVE_HEADERS_FROM_EMBEDDED_BUNDLES = NO
For Release: REMOVE_HEADERS_FROM_EMBEDDED_BUNDLES = YES
This fixed the issue for me.
Try to restart Xcode. In my case it resolved an issue.
In my case there was a compiler error in the "C" code which was reported in LLDB, after fixing the error LLDB started working again.
As suggested by Tim https://stackoverflow.com/a/41876400/1840269 the root cause to our problem was a matter of duplicates.
We had a obj-c wrapper category for SDWebImage that was used from both obj-c and Swift.
When Importing the category from Swift everything blew up because of redefinition/duplicate import since the SDWebImage pod already exposed it self as a Swift module.
The solution? We re-implemented the obj-c category as a Swift extension - and kept using it from both Swift and obj-c by adding #objc in front of the extension and importing the #import "product-Swift.h" file from obj-c.
And maybe start with checking: https://developer.apple.com/library/content/qa/qa1947/_index.html.
I just took 2 days for me to resolve and debugging through print command all the time. Now I got the issue:
My project is in Swift and I was using objective-C library same as imported in pods for swift(old Objective-C project merged in this one) and was using import IQKeyboardManager as well as import "IQKeyboardManager.h" header as well. That conflicts and deleting the header one resolved my issue finally.
You can check with this type of duplicity in libraries.
Is there anything in swift that works like frameworks list in Xcode while using Obj-C? I want to know what modules I can use by default. e.g.. CoreData, CoreImage, etc.
Method - 1
To use any Objective-C Framework in Swift, you need to create 'Bridging-header.h" file and import your framework there to use anywhere in your swift project.
To add Bridging header in Swift Project
Method - 2
You can direct import any framework.
E.g. import CoreData
The main problem is that Xcode doesn't provide "AutoComplete" option for "import" statement so that's the problem as of now.
Reference: Import Framework in Swift Project, Xcode
Edited:
Most Popular List of Swift Modules which you can get from Xcode:
https://github.com/andelf/Defines-Swift
I'm new to XCode and Objective C / Swift. I'm trying to make a Swift library project that doesn't depend on cocoa or anything. So it's just Swift files. What type of project should I be creating (I'm assuming there are multiple ways of doing this? How do I need to configure the project so that it builds to a .so file? And finally, how do I build it to a .so file?
I'm using Xcode6-beta.
You can create a Swift library for iOS by creating a new Xcode Project and selecting iOS/OS X -> Framework & Library -> Cocoa Touch Framework and then setting the language to Swift on the next screen.
Once this project has been created you are not required to link against the Cocoa frameworks, and can remove any references to them if needed.
Upon compiling this project Xcode will create a .framework folder in your build directory which contains a dynamic library which you should then be able to link against. Note however that I haven't had any success myself yet at linking directly against this file, even though it appears to be a standard dynamic library.
In terms of using this shared object file on Android I believe you will be out of luck, as the Swift language (much like Objective-C) requires a runtime library which is simply not available on other platforms at this time.
... I think you are limiting your train of thought a bit or expecting leaps and bounds to quickly swift is ready to work with objective c and cocoa so you aren't going to be able completely avoid cocoa however you wont have to write any of it the compiler will do that for you. but you will still have to use cocoa frameworks or modules like foundation( contains many specialized objects for program development), UIKit, CoreData however these don't require you to write the cocoa. and if Im not mistaken the .so file is made on compile so you never actually touch that file but rather is supporting files .swift
to do it
if your looking to do everything programmatically or if you want to xib or storyboards just make a new project I prefer an empty project.(set programming language to swift and decide if you want core data or not finish the project wizard thing and bam you have a YourAppDelegate.swift you can make another .swift file or a storyboard and hopefully you know what to do from there. Swift book is available on ibooks for free its nicely written
although it will be quite a while before cocoa and swift are completely separate... if ever