Xcode 13.1 bug editing dependency as local - swift

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.

Related

Xcode: Own Swift packages missing in Schema selector

I have some SPM swift packages as part of my swift project.
After some Xcode crashes, those packages don't appear in the Schema selector (black arrow in image) any more.
So I can't select and build the swift packages any more separately.
What can I do to fix this?
For me it was solved by deleting .swiftpm/ folder
(Although, maybe just removing xcshareddata would've been enough)
Steps:
Removing dependency + reference from the main project
Delete .swiftpm/ of "problematic" local package
Add the package dependency back to the project
At least it worked.. Hoping there's a better way to solve this as well.
There must be a better way to resolve this, but at least it works:
Usual housekeeping:
Clear derived data
File -> Packages -> Reset Package Caches
restart Xcode
For each package that Xcode doesn't find / build:
Klick on package -> show in Finder
in finder, move the whole package into a temporary folder (package in Xcode gets red)
delete red package in Xcode
Create package again in Xcode with the same name (File -> New -> Package...), add package to appropriate targets again
remove the newly generated swift files in XCode, including Package.swift
drag the files in your copied folder into the corresponding place in the Xcode package
File -> Packages -> Reset Package Caches (for some reason Xcode loses external packages each iteration)
Build -> should be one less missing package in the error messages

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.

Adding Local dependencies in XCode11 using SPM

Is it posible to integrate local dependencies with SPM in xcode 11,
File > Swift Packages > Add Package dependency...
It only seems to populate and let me select git repos hosted on bitbucket
I am just not sure if I am approaching the issue the correct way, maybe I should be using a Package.swift file instead? I have a lot of experience with Cocoapods but I would like to branch out and try other tools, especially if they are going to be supported in xcode as it seams SPM will be (Im using xcode11 beta 5)
This is the way I did it :
Drag and drop your package folder (in my example "DataStructures") from the finder directly into the Frameworks group of your target. You will see that the dropped item take a brown folder color (you can use the arrow to "get into it").
Go to your project target page, in the "Framework and Libraries" click the "+" button. Your package should show up in the "Workspace" area as a library.
Xcode 12
If you have a remote version of your package already in the project and want to work on a local. There are a few extra steps...
1. Make sure your local package's version is higher than the remote version
If you don't do that, it will continue to fetch the remote package
Select your project in Project Navigator
In the main window select Swift Packages
Select the package you want to replace with a local and remove it
Go to File > Swift Packages > Add Package Dependency...
Drag the your local package folder to the package search bar and add the prefix file://
Click on Next
Confirm that the minimum version is higher than the remote one.
Yep, Xcode makes this rudimentary task unnecessary difficult.
The trick is simple, though: in the sheet that pops up when you select 'Add Package Dependency…', in the URL field, you can enter a file:// URL. e.g. drag the package's folder into that field, which will place the path in it - e.g. '/Users/me/Documents/myShinyPackage/', then stick 'file://' to the front of it, and you'll be able to proceed.
Addendum: as some folks note in the comments below, this is problematic if you share the project with others, unless you standardise on paths. For individual use, however, it's fine.
Local Swift Package Manager(SPM)
[Dependency manager]
Key point is: file:// + git which you can use it in URL field
file://<path>
//e.g.
file:///Users/alex/Desktop/MyProject
Notes:
It works with git repository that is why please make sure that you committed your changes beforehand
when you add a SPM dependency File -> Swift Packages -> Add Package Dependency it is added into project -> Swift Packages and implicit dependency[About] is added to Frameworks, Libraries, and Embedded Content
when you committed new changes into framework do not forget File -> Swift Packages -> Update to Latest Package Versions
Product folder
<path_derived_data>/<randomizer>/Build/Products/Debug
//e.g.
/Users/alex/Library/Developer/Xcode/DerivedData/SPMExperiments-bmmqumztjedpekaajffnaegxzwzg/Build/Products/Debug
[Local CocoaPods]
[Local Carthage]
A new way(2022.11):
Simply drag the local package repo to your main project
Like this
Note: if you have that package open in another Xcode project you have to close it first.
By this way, Xcode will ignore the remote package in SPM. You can edit the local package repo directly and use it in main project.

Difficulties adding ShareKit to project

Okay, so I seem to be having a bit of difficulty in adding ShareKit to my project.
I've downloaded the latest version via Git. I'm dragging and dropping the 'ShareKit' folder from Finder because you can't do it drag and drop from the xcode project.
I've figured out how to ignore ARC by setting ShareKit files to -fno-objc-arc in my Target > Build Phases> Compile Sources. So that gets rid of my arc warnings.
However, how do I get my "Submodules" folder to come along too? In the ShareKit project it doesn't appear in the xcode folder hierarchy, but it is in the project folder and you can access it through Finder. Sharekit's demo project compiles fine.
So without Submodules, I get errors like "SSKeyChain.h not found" (https://github.com/ShareKit/ShareKit/issues/191) among others. So I drag and drop the entire Submodules folder into my project, and that solves some, but creates others. The Submodules folder is very convoluted and I'll see errors referring to lines trying to import Cocoa/Cocoa.h, which is for mac and not iOS I believe. Some of the Submodules files are looking for files like "SampleAPIKey.h" and if they're not there, hell if I know why they aren't.
Has anyone had experience with figuring out how to do this?
Note: Wednesday, September 19, 2012
In a project that I use ShareKit, after building in Xcode 4.5, in I was getting a number of warnings and additionally a fatal error when trying to build for the iOS 6 Simulator. After having problems updating the ShareKit code via the instructions in the ShareKit github FAQ I decided to remove and then read SK to my project from scratch. The new install instructions that on github are greatly revised and following step by step worked without a hitch, so the work around that I previously provided is most likely out of date.
End of note Wednesday, September 19, 2012
I had some difficulty doing this myself but did get it working. Assuming that you are using Xcode 4.x make sure that you follow the directions in Step 2 of the install instructions re that version, but it took a number of tries as the instructions were not perfectly clear to me.
What worked for me was to 1) drag the Submodules/ShareKit.xcodeproj file from the Finder to the project I was adding SK to at the bottom of the tree navigator UNDER the other groups and NOT adding it as if it was an additional project necessitating creating a workspace, 2) then, I dragged the Classes/ShareKit folder from the tree under the newly dragged ShareKit.xcodeproject into the main project tree and when prompted choose "Create folder references for any added folders", and finally 3) delete the ShareKit.xcodeproject and click "Remove Reference Only".
Hope this helps.

is there any way to solve 'com.apple.product-type.framework' issue?

I am trying to implement cover flow effect in my application by using objectiveFlickr project, But it shows
"target specifies product type 'com.apple.product-type.framework', but there's no such product type for the 'iphonesimulator' platform"
error whenever I am going to be run the application.
Note: I have included all the framework and objectiveflickr library.
I have made necessary changes in project setting.
There is any solution available for this issues or shall I follow with another sample?
I just ran into the same problem. Something in my project got messed up as I switched back and forth between Mac targets and iOS targets, causing Xcode to become confused. Reverting the project.pbxproj file inside the xcodeproj package didn't fix the problem. Deleting my entire source tree and updating it from source control did fix the problem.
This leads me to believe that the problem lies in the other files inside the xcodeproj package. Try the following:
Close your project in Xcode.
Navigate into your xcodeproj package (either through Terminal, or in Finder by right-clicking and selecting "Show Package Contents")
Delete your pbxuser and perspectivev3 files. They will be re-created.
Open your project in Xcode.