I've written a working swift prototype. It contains a parent class and some subclasses. I want to be able to import the parent class into another project where I will create sub classes for it.
I created a new XCode project for a dynamic library, added the parent class to it and ran build. I've seen where you can't use static for Swift code.
I also created a different directory and set up a swift package. The build on it ran successfully.
When I add an import statement to the project where I want to use it, it says it can't find it. The statement is: "import RailsData", the name of the parent class.
I've tried adding the dynamic library project to "Linked Frameworks and Libraries". I also tried adding the swift file directly. XCode flags the import as not found.
The swift package manager example is all command line based so I'm not sure if will work with XCode projects. I would eventually like to make a package out of it.
Xcode 8.2, Swift 3.0. I'm pretty sure I'm missing something fundamental.
Update
I found a related question. It says to
Put your package manifest file into the same directory as the Xcode project, and then invoke swift package generate-xcodeproj
With a search I found this page that says:
Instructions for how to build a package are provided by the Package.swift manifest file.
So I copied the file to the root of my project and ran the command above. It created a new .xcodeproj. When I opened it, I saw my original files, but not anything from the package. That's not surprising as there is no reference to it's location in the file system. Also a mystery is what happens when you want additional packages. Do you keep generating new projects?
It seems like the missing link is the following command
swift package generate-xcodeproj
Actually Adding Swift 3 packages to Xcode 8 using the Swift package manager should answer your question.
Related
I am faced with a strange issue. I recently rebuilt my Xcode project file using a tool called Xcode gen, I now have hundreds of errors in my files related to imports, for example:
import Foundation
struct BillingHistoryDetailTableCellViewModel {
let contentColor: UIColor?
// Implementation
}
error: Cannot find type 'UIColor' in scope
Why am I suddenly faced with this error now? Xcode had no issue compiling this kind of file before.
Is there some kind of setting or flag required to fix this?
Answering this for others:
If your project happens to include objective-c code and the bridge file includes imports to frameworks that use UIKit then this will be imported globally across your project, hence Xcode not asking for the import in files where you reference objects in UIKit.
This seems kinda like a bad side effect of using an objective c bridge as it's easy to miss the adding the import statements.
I have created a framework that contains code useful for testing (a bunch of convenience initializers, for example). Now I would like to import that framework in a test target but there doesn't seem to be a way to do this in Xcode. Just importing it with import Dependency gives me the "Module not found" error when building.
The General tab of the test target does not have any settings for that (or any settings):
The Build Phase tab has a Dependencies section, but the framework I want to add does not show up in the list when I press the + button:
There's also a Link Binary with Libraries section, but when I try to select the framework there Xcode says that file is already being linked (where?):
I can import and use the framework if I add it in the Frameworks, Libraries and Embedded Content section of the main target, but I don't want to do this since the framework is meant to be used only in the test code. I don't see the reason to pollute the namespace with all the extra initializers. I could probably try to check if no XCTest classes are available at runtime and crash, but that seems like a workaround rather than a solution.
Any advice?
P.S. I'm using the latest version of Xcode (11.3.1).
If you have a source code you are able to use Explicit dependency[About] with cross-project reference
drag and drop dependency project inside a test target
Build Phases -> Dependencies -> Plus(If you didn't include dependency into test target on previous step)
Import
[Mixing Objective-C and Swift]
Xcode 12
Drag and drop the framework into folder where tests are located.
Go to YourAppTests target settings: Build phases -> Link Binary With Libraries – here your framework should be listed, if not tap on + button -> Add other (on the bottom) and choose your framework from project's test folder
Done!
PS: most likely works for Xcode 11 as well
I've been trying to learn Swift 4, and therefore needed to use Xcode9 Beta as the IDE. I would like to load a large CSV data file to do some data analysis using a playground. The library I'm trying to use is CSVImporter, installed using Carthage, as recommended by the developer.
I've spent a week on this issue, trying to follow guides I've found online, such as here - Stackoverflow, here - Medium, but they all refer to previous versions of Swift and Xcode, and none seem to work.
In general their approach seems to be incorporating the playground into workspace with a project that uses the imported resource. I usually get the "No such module 'CSVImporter'".
My specific question is: How do I set up a Swift 4 Playground so that I can import CSVImporter with Xcode 9 Beta?
While I have this specific task, I think this would be of general interest to the community. I suspect that someone with a far clearer idea than I of how Xcode executes builds and resolves build dependencies would be able to address this fairly easily! Many thanks.
Basically, you have it right. Approach is:
Create new XCode project for Cocoa Framework under MacOS
Create Cartfile with your dependencies
Build dependencies (e.g. carthage update --platform macOS)
Import the .framework files that were built (from Carthage/Build/Mac)
Create extra build phases step that will run script /usr/local/bin/carthage copy-frameworks and copy imported frameworks (just follow Carthage's guidelines, it's all the same so far)
Create some .swift file (e.g. main.swift) that will just import frameworks that you have imported via Carthage
Save XCode project as a workspace file
Create new playground (also MacOS) and save it under the projects root folder of your "fake" framework
Add the playground into workspace (as of XCode 9 it's not possible to create playgrounds directly in the projects/workspaces, so you need to do this trick with adding an existing file to the workspace)
Build your project
In the playground file, import your "fake" framework (see step 1), and only after import your carthage dependency framework.
Profit
If your external libraries are SPM packages you can create a playground with Arena:
arena https://github.com/finestructure/Gala
🔧 resolving package dependencies
📔 libraries found: Gala
✅ created project in folder 'SPM-Playground'
Is there a way to include a (non-Apple) framework in the "SupportCode.swift" file, in the Sources directory of a Playground?
While the framework is successfully imported when the import directive is placed in the Playground itself, I get a "No such module" error popping up when trying to import the same framework in SupportCode.swift.
I have my playground embedded in a workplace with the required frameworks added to it as well.
It is a hack. if you have file like "Parse.framework", just copy it to Xcode's system frameworks folder at "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks"
Now you can import this framework in playground just like any other system framework.
This didn't work until recently.
In order to import an external framework, you have to have the playground and your framework's target/project in an Xcode Workspace. Once you have that and you build the framework, you can just import the framework with an import.
If the playground is already in a project that is not a workspace file, you can convert the project to a workspace by choosing File > Save As Workspace then add the playground to that workspace.
You can also drag the framework project in the Finder to the project navigator in the workspace.
Open the playground file in the editor, and add import the custom framework using an import statement.
NOTE: These are the conditions.
The framework is in the same workspace as the playground.
The framework has already been built.
If it is an iOS framework, it is built for a 64-bit run-time
destination.
The workspace contains at least one active scheme that builds a
target.
If it is an Objective-C framework, it sets the Defines Module build
setting to Yes.
I have found this tutorial exactly how I was doing in my project.
https://m.pardel.net/using-3rd-party-frameworks-in-swift-playgrounds-fd415f6dba10
Please don't miss to add empty .swift file in your project as describe in this answer https://stackoverflow.com/a/47922876/855261
I created a new very easy Acceleo project, with just one main module generate.mtl that tries to create a new file. The package is exported in the Manifest. When I launch the .mtl file, I get this error
!MESSAGE Couldn't load class org.eclipse.acceleo.module.sample.main.Generate. Check that its containing package is exported.
!MESSAGE Couldn't load class org.eclipse.acceleo.module.sample.main.Generate from project org.eclipse.acceleo.module.sample
I don't really know why and what to do.
I had a similar problem and I solved it by adding the bin directory to the classpath in the Manifest file.
I did this because of Etienne's answer here: Can't generate java from UML using Acceleo in Eclipse1
When you open up the MANIFEST.MF with the "Plugin Manifest Editor", there is a "Runtime" tab at the bottom. On the right side bottom of that screen there is a place to edit the classpath. I added "bin/"
After that, I had no problems with loading the class.
I solved using the version 3.4 of Acceleo, instead of the 3.5. The 3.4 works
Your solution #jpcahoon - Solved my problem with Acceleo 3.5.1
I had the same problem today despite having the Classpath declared in the Manifest file.
The solution for me was to tweak the Execution Environment in the Overview tab of the manifest file (In my case, setting it to JavaSE-1.6 solved the problem).