References to Removed Framework in project.pbxproj File - ios

I recently removed a framework from my iOS project and am installing it instead through a dependency manager (CocoaPods). I noticed, however, when checking my changes in to source control that some references to the framework were removed, but one was added with an absolute path. From the diff (the first line was removed and the second line added to my project file):
- 767C7EC51DB295CE00A8850F /* TealiumIOSLifecycle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = TealiumIOSLifecycle.framework; sourceTree = "<group>"; };
+ 767C7EC51DB295CE00A8850F /* TealiumIOSLifecycle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TealiumIOSLifecycle.framework; path = /Users/jal/workspace/com.myapp/MyApp/Shared/ThirdParty/TealiumIOSLifecycle.framework; sourceTree = "<absolute>"; };
There is no file at that path on my local machine, and I was able to make a fresh clone in a separate directory and on other machines with a different directory structure and was able to build the project without any warnings or errors. The physical file of the framework no longer exists in the project directory (when I removed the file from the project in Xcode, I chose "move to trash).
Is this normal? If not, how can I remove these references?
To be clear, there are no references to this framework anywhere in the project. This includes Linked Frameworks and Libraries, Link Binary with Libraries, Target Dependencies, Embed Frameworks, etc.

Tap on your project file in xcode and in the General tab scroll down and check that it is not included in the following sections
The missing frameworks would be probably highlighted in red (or faded in gray i don't remember exactly)
Also in the build phases check it's not being tried to be copied

Related

How to check SPM repo link in xcode?

I am trying to check repo link for my existing project already added SPM.
I want to know the repo link for github/bitbuckect etc etc.
Why i wanted to know this - I have one existing project in which lots of SPMs are there. and I want to add all that SPM in my new project but I don’t know git links for those SPM.
Is there any way to do that?
Thank you for help.
If you have a Package.swift file in the root of your repo, that should also contain the links, if not, try the below one:
On the left pane, each of the dependencies will have a .podspec file with a s.source specification. You can find the URL there.
The root source of this information can be found inside the project file (./<project_name>.xcodeproj/project.pbxproj). Just open it with text editor and search for occurrences of XCRemoteSwiftPackageReference. You should be able to find sections like this one:
/* Begin XCRemoteSwiftPackageReference section */
A1BFE4BB2779F1410015B840 /* XCRemoteSwiftPackageReference "swift-atomics" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/swift-atomics.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */

Strange path of new file in Xcode 10.3

When I add a new file in normal way using 'File > New > File' in the project the file path in the project is set with strange prefix. In the pbxproj file:
B28A19422E8761000F9E8AC /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = File.swift; path = "../../../../../../../../../System/Volumes/Data/Users/<USER>/Documents/work/<Project>/File.swift"; sourceTree = "<group>"; };
So, it leads to crash while building on another Mac.
How can I fix it?
As I found, simple drag and drop of the file works after removing reference and returning the file back to the project. You shouldn't use 'Copy items if needed'. It seems, this is Xcode bug.
Looks like you are using absolute path to your project files.
Try marking the Copy items if needed option when adding the files. It should solve the problem.

Xcode Projects: Is it possible to programmatically determine the path to a Library?

I have an entry like this in my pbxproj file:
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
The part of it I'm interested is this line:
path = "../node_modules/react-native/React/React.xcodeproj";
Is there a way to modify this so I could get the path to the react-native folder programatically?
Like, if this were a bash script, I could use an expansion like so:
"$(run-some-script)/React/React.xcodeproj"
I could make a script that the user could run to automatically update the paths in the pbxproj whenever they change, but I am curious if I could have a way to have Xcode run a command to get the path to this React.xcodeproj file whenever it is opened.
Short answer is no, but you can place other source code or a library files inside the toplevel xcode project directory and then reference these files as relative paths. That way, you can link to the project relative files and then update them and the xcode build will just make use of them. For example, you can include source code that is under a completely different git repo in a subdirectory, then you can update that code differently that the toplevel source, and yet still build the whole combined project together.

xcodeproj adds framework but linker can't find it

I'm adding a custom framework to my Xcode project using the xcodeproj Ruby Gem:
top_group = project.groups[0]
framework_ref = top_group.new_file(framework_path)
target = project.targets[0]
target.frameworks_build_phase.add_file_reference(framework_ref)
When I then open Xcode and look at the target, the framework is listed correctly under Linked Frameworks and Libraries, yet the linker complains that the framework cannot be found when building. Dragging the framework in the Linked Frameworks list in Xcode fixes it, and I can build successfully.
Why? Dragging seems to force Xcode to regenerate the project.pbxproj and add a missing reference. What would that be?
you need to set the path where your framework is!
append the path in build settings for "FRAMEWORK_SEARCH_PATHS"
settings = target.build_settings("Debug")
settings["FRAMEWORK_SEARCH_PATHS"] = [settings["FRAMEWORK_SEARCH_PATHS"], your_framework_directory ]
or
settings["FRAMEWORK_SEARCH_PATHS"] = settings["FRAMEWORK_SEARCH_PATHS"] + " " + your_framework_directory ]
Append the path in build setting as follows:
#Add framework search path
settings = target.build_settings("Release")
settings["FRAMEWORK_SEARCH_PATHS"] = Array(settings["FRAMEWORK_SEARCH_PATHS"])<< '$(PROJECT_DIR)/SDK'
settings["LIBRARY_SEARCH_PATHS"] = Array(settings["LIBRARY_SEARCH_PATHS"])<< '$(PROJECT_DIR)/SDK'

XCode Cant' Edit CoreData Model

After adding a CoreData Model to my existing project using
File > New > File... > Core Data > Data Model
I am unable to edit the model. The project now includes a .xcdatamodeld package reference, but clicking on it in Project Navigator has the same effect as clicking on a folder or group, the current editor does not change. Also right clicking the reference and selecting "Open As >" lists no potential editors. Furthermore, opening the file inspector panel only lists settings for "Identity" "Target Membership" and "Text Settings", it does not list settings for "Core Data Model" or "Versioned Core Data Model"
Not that this should have any effect on XCodes ability to recognize a file type, but I have also referenced CoreData.framework in build phases, and included the necessary Core Data properties in the AppDelegate.
What's strange is I have opened the .xcdatamodeld package in Finder to expose the internal .xcdatamodel (note no trailing 'd'). Double clicking that file will open XCode with the Core Data Model Editor as expected.
Even stranger still is, I created a new projected and clicked the "Use Core Data" check box. Doing so allowed me edit the data model by selecting the .xcdatamodeld reference in the Project Navigator. Hence my machine and XCode are capable and configured to edit CoreData files.
It's as if XCode is unable to use Core Data unless the original project was created with the "Use Core Data" check box.
Has anyone experienced this issue, were you able to fix it, and how?
Thanks!
Turns out I was attempting to add the Data Model to a group which referenced a specific folder in which to store it's children. That folder however did not exist. This cause XCode to place the data model in the project root, but at the same time reference it as residing 2 directories above the project root. What's even odder is that XCode didn't list the file as missing by displaying it in red. Either way XCode ignored the file when clicked in Project Navigator, because it didn't really exist where it thought it did. Moral of the story is: check your file paths and configured group paths.
I ran into this issue today, and the problem was that my .xcdatamodel file was packaged inside itself (strange, I know). Here's how I fixed it:
I found my File.xcdatamodel file in Finder.
Right-clicked and selected Show Package Contents.
Inside was another copy of File.xcdatamodel. I copied that to my Desktop.
I then dragged that file into Xcode and it opened.
What a relief. :) I hope this helps someone else.
Our real problem was that Xcode couldn't open/validate the data model when creating a new version.
Meaning: having first one .xcdatamodel and then Editor > Add Model Version... > MyProject 2 (as .xcdatamodel).
After what, the MyPoject.xcdatamodeld was created but couldn't be opened.
After hours investigating we figured out that the .xcurrentversion file and the XCVersionGroup in the project file were missing or invalid.
One of the reason was that the xcdatamodeld version should be in the root folder.
Easy Fast Solution 1:
Create a new Model Version and:
Set the path to the root folder
Specify the Group to be the subdirectory where the previous version is.
The new .xcdatamodeld will now work on Xcode but can't be moved anywhere else than the root folder.
Complicated Solution 2:
To have a wroking .xcdatamodeld in a subfolder, hou have to modify manually the project file follwoing those steps:
PS: This is the most complicated and hacky answer I evcer wrote. I'm sorry :(
Create a new Model Version (even though it invalidates the data model) in the same directory of the previous version.
Make sure the new .xcdatamodeld file is specified in your target(s).
Open the Package Content in Finder and drag-and-drop all xcdatamodel versions to the project.
Open the project.pbxproj file in a text editor.
Search for the new files for all data models and copy their fileId.
Example:
75F3199D1B9D80D50030FF46 /* MyProject 2.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = 75F319981B9D80D50030FF46 /* MyProject 2.xcdatamodel */; };
// fileId = 75F3199D1B9D80D50030FF46 /* The first id at the beginning of the line */
Move those lines from the PBXBuildFile section to the beginning of the PBXFileReference one and update them like this (reuse the fileId).
Example:
75F3199D1B9D80D50030FF46 /* MyProject 2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MyProject 2.xcdatamodel"; sourceTree = "<group>"; };
Now search the file MyPoject.xcdatamodeld in the PBXBuildFile section and copy its fileRef.
Example:
75F319961B9D7FA50030FF46 /* MyProject.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 75F319931B9D7FA50030FF46 /* MyProject.xcdatamodeld */; };
// fileRef = 75F319931B9D7FA50030FF46
Finally, at the very end of the project.pbxproj file create the XCVersionGroup section and reuse the fileRef from the xcdatamodeld and all fileId.
Example (without the // comments):
/* Begin XCVersionGroup section */
75F319931B9D7FA50030FF46 /* MyProject.xcdatamodeld */ = { // fileRed
isa = XCVersionGroup;
children = (
75F3199D1B9D80D50030FF46 /* MyProject 2.xcdatamodel */, // fileId
75F319A11B9D80D50030FF46 /* MyProject.xcdatamodel */, // fileId
);
currentVersion = 75F3199D1B9D80D50030FF46 /* MyProject 2.xcdatamodel */; // fileId of the current version
name = MyProject.xcdatamodeld;
path = Path/To/MyProject.xcdatamodeld; // set the correct path
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
};
/* End XCVersionGroup section */
};
rootObject = 7564EB681B4AB1560065394B /* Project object */;
} /* EOF */
You should now be able to open the xcdatamodeld file in Xcode now from the desired subfolder.
Now remove the extra references of the single xcdatamodel files from xcode (the ones created in the beginning).
Sorry for the long answer... but problem solved :D
This is still a problem in Xcode 8.
For me, the simple solution was to drag (inside the project file navigator pane - left hand side of Xcode) my .xcdatamodeld file from its (yellow) sub group folder up to the very top level under the App (the one with the blue icon).
After that, it opened up with the editor immediately.
I retested by dragging it back to the sub-group, and again it would not open in the editor, then back to top level and it opened correctly...
I have no idea why this is happening, but at least I can edit it again.
Hope this helps somebody.
Restarting Xcode usually takes care of this problem.
Here's how I solved the issue:
In Xcode file tree, deleted the .xcdatamodeld file.
When I opened the project folder, the file was there. (Xcode only removed the reference.)
I've dragged it back to Xcode file tree, checked "Copy items if needed". It didn't make a copy because understood that the file is already under the project folder.
Problem solved.
On first selection this behavior happens but selecting another class then back to the dataModel allows editing for me on a fresh project without CoreData then adding the coreData model to the project.
Just a thought, did you add an entity or are you not even able to access the datamodel view?
I solved it like this in Xcode:
Right click on your project (not your project folder, I mean that one with the blue Xcode Icon!), than select "New File" and choose the right folder to save the data model.
Note: Clicking "New File" on the project folder itself or on one of its subfolders did not work somehow..

Resources