Importing a Swift project from Linux to Mac - swift

I used CLion and its Swift plugin to start work on a little Swift project. I uploaded the current status to github and now want to work on that on my mac (I followed this tutorial: https://blog.jetbrains.com/clion/2015/12/swift-plugin-for-clion/). How do i import that project on mac now, though? I have AppCode and XCode installed but cant really get it to work. I used AppCode's "import from github" feature but that leaves me with a project that does show the CMakeLists.txt and Package.swift, but not my Sources/ folder at all. And in XCode i can only start new projects for applications, not a static command line lib without any GUI like this project is supposed to be.
So: How do i import them on mac in AppCode (preferred!) or XCode?
Thanks!
EDIT: Oh an when trying to simply checkout my github repo in AppCode it states "no project file found".

It sounds like you've created a SwiftPM package, since you have a Sources directory and a Package.swift file. If that is correct, you can create an Xcode project with the following command:
swift package generate-xcodeproj

AppCode needs xcodeproj to open the project, without it you cannot open it in AppCode. But you can use the CLion on Mac.

Related

Editing a Package Dependency as a Local Package

Overview
I have a project that uses a remote swift package.
I would like to edit this package in the same project so that I can refine it based on the usage.
Aim:
To do this I am trying to add the same package as a local package so that I can edit it.
Reference:
https://developer.apple.com/documentation/swift_packages/editing_a_package_dependency_as_a_local_package
Problem:
When I drag and drop the cloned folder containing Package.swift into the project, I can't see any of the local package source files in the project. (see screenshot)
I have been breaking my head over it. Any help on this would be much appreciated.
Xcode Version:
13.2 (13C90) (downloaded from the developer portal not the AppStore)
The reason you cannot see the content of the package is that you have it open in another Xcode instance.
You can only edit a package in one Xcode instance at a time.
I find closing down Xcode completely, then opening up the particular project that I want to edit the package in solves the problem.

Xcode 13.1 bug editing dependency as local

Just upgraded to Xcode 13.1 and opened a SPM project by clicking the Package.swift file that has some dependencies.
In the former versions I could simply edit one of these dependencies by dragging a local clone of the package into the Project Navigator.
Xcode was then going to ignore the checked out dependency and let me edit the local one.
Apple documents this here.
When trying this with Xcode 13.1, Xcode just copies the folder into the project folder, like it does with normal files/folders that are not SPM projects.
Did I find a bug or missed I something?
Thanks!
Update: I found out how to work around by creating a .xcodeproj file with swift package generate-xcodeproj. There I could drag in the package as always. This works but is not the way to go, as the xcodeproj generation is deprecated by apple.
It looks like there is now an Add Local... button at the bottom of the add package wizard. Selecting the package from your local filesystem yields the same result as the "drag from finder" instructions you've linked.
The wizard is accessible from:
File > Add Packages, or
Project.xcodeproj > Package Dependencies > +.
I was having this problem, too, but after seeing the first comment on the other answer, I tried this:
I used File->Add Packages->Add Local…->navigate to local clone of dependency->Copy Package, which indeed seems to do nothing, but it puts a .package dependency line onto the clipboard.
I then edited my main project’s Package.swift to replace the existing Github dependency with the contents of the clipboard. Now I can edit the dependency’s files directly in the “Package Dependencies” portion of the project contents pane (which I wish you could do for a regular Xcode project too).
This solution kinda sucks, because it forces me to modify Package.swift, which means everyone on the team has to set things up the same way. Fortunately, I'm the only one working on this project, but future me is sure to be bitten by this.

VS Code cant find references to some Unity Classes

So, i just upgraded my Visual Studio Code Package from 1.2.3 to 1.2.4 and then it cant find the references to Cinemachine, UI and TextMeshPro anymore. With any other code editor it works well, even with Visual Studio 2019.I'm using Unity 2021.1.3f, and i cant find were to downgrade the version of the VS Code package.
Use the Unity Package Manager window (in Unity’s top menu: Window > Package Manager) to view which packages are available for installation or already installed in your project. In addition, you can use this window to install, remove, or update packages for each project.
Ok, so i found a solution, but its kinda weird and i hope they fix it by the next unity update.
for Unity 2021.1.3f1
First you need to create another Unity project. The VS Code package already come in the 1.2.3 version from default.
Close Unity after the project is created.
After that you need to copy the "Assets" folder and the "Project Settings" folder to your new project. Unfortunatly you have to manually install any package that you project depends on manually (Because i dont know how to copy/paste any package from one project to another) and after that dont update the VS Code package again.
I higly recomend creating a copy of your project (or having it in a git repository) before updating any package because Unity dont let you downgrade packages anymore.

How to import a swift package that is using an older version of Swift tools?

I was trying to open a package, namely trying to import and run the swift folder under this repository.
When I Open->Package.swift file in XCode 11, it actually opened all the files under that directory. So, I thought I am one step close to running it.
But now I’m getting an error when I try to build it:
package at RepositoryName/swift’ is using Swift tools version 3.1.0 which is no longer supported; consider using ‘// swift-tools-version:5.1’ to specify the current tools version
So, I was wondering if there is a way to import and use this swift package that uses the older swift tools version?
Thanks
I solved this problem by recreating the package on XCode 11 with the same name and putting all files in the new package.
XCode provided already the Package.swift file so I didn't touch it. The first line describes the Swift tools version.
While adding it as a new package from File -> New -> Swift Package: I did set the "Add to" and "Group" to project name. And also I created the package inside this project folder.
I also added the package to target, selecting Target name -> General tab -> Frameworks, Libraries and Embedded Content -> + button to select it from the list.
Then within my project viewController I added
import [PackageNameHere]
Later on, I decided not to use it as a package, but in case anyone wants to do that this is how I did it.

How to use frameworks imported with carthage in swift playground

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 :(
This stopped working at some point. Sigh
What I do now is
Create a macOS > Command Line Tool.
Create a Cartfile with github "ReactiveX/RxSwift" and run carthage update --platform iOS
Go to the command line tool target and add the frameworks from Carthage/Build/iOS in Linked frameworks and Libraries
Add the playground files.
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
Create a Cartfile with this line: github "ReactiveX/RxSwift" "swift4.0"
Run Carthage with carthage update --platform iOS.
Add a playground to the project.
Click File > New > Playground…
Choose the iOS > Blank template and name it Rx.playground
Right click the project node and choose “Add Files to RxPlayground”.
Select the Rx.playground and add it.
Create a workspace
Click File > Save as Workspace…
Save as Rx.xcworkspace
Copy the frameworks to the products directory.
Close the project and open the Rx.xcworkspace
Create a Cross-platform > Other > Aggregate. Name it RxAggregate
Create a New Run Script Phase with the following content:
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.
In order for the framework to work within a playground, the project that produces the framework must be included in the workspace for your project. So to make this work you need to follow these steps:
If your project is not inside a workspace, create a workspace for your project by choosing File > Save As Workspace in Xcode.
Drag the .xcodeproj file from the Carthage/Checkouts folder into your workspace.
Run the build action on your framework target.
I solved it by copying the built frameworks to the Built Products Directory, where Playgrounds in the workspace also searches for frameworks.
Note: you also need to run lipo and strip away unused architectures from the FAT binaries.
See more here:
https://github.com/richardnees/CarthagePlaygrounds
Based #Jano's great answer (thanks for that), I created a fully functional playground to interact with Carthage frameworks:
https://github.com/backslash-f/carthage-playground
I included the Charts framework as an example:
I tested with latest Xcode.
"Works on my machine." 👍🏻
Found how to do this without converting to workspace and adding .xcodeproj file from the Carthage/Checkouts folder into your project.
This works if you have some framework target that contains all sources you want to use in playground. This framework must be in "Embedded frameworks" of your main target.
Add Carthage .framework to your project from Carthage/Build/IOS
Drag and drop it from your project tree into "Embedded
frameworks" for your main target
Add Carthage .framework to your
framework target as Optional(In target Membership)
Add import
"Your framework target" into playground
That worked for me