How to develop and test an iOS framework in XCode - ios

I have followed a tutorial on iOS-Framework. On the last part "Developing the Framework as a Dependent Project", I have created the framework project and a test project which includes the framework.
However, when I try to open at the same time both projects in XCode, I am getting :
Cannot open "MyLib.xcodeproj" because it is already open in another workspace.
How can I develop my framework and test it every 30 seconds like all the developers do?
I am using XCode 4.6.2.

The solution is to create an XCode workspace:
Choose File > New > New Workspace.
Enter the workspace name, and specify its location in your file system.
Click Save.
In the project navigator, Control-click in the empty space below the list.
Choose Add Files to “YourWorkspace”.
Navigate into the folder containing the project package.
Select the framework project xcodeproj and click Add.
Redo the steps 4 to 7 for the test project
I found the workspace documentation in the XCode User Guide.

Related

Work with Frameworks in Swift

I'm following this steps and works perfect, but i need something additional.
Each time when i do any change, is necessary remove the .framework file from parent project and go to framework project and generate a build again and drag and drop into the parent project AGAIN.
It's possible make a reference in where only need run the framework project to see the changes in the parent project without need follow all this steps?
Build your framework in your framework project , right click on the .framework file in build folder , show in finder , drag it to your parent project , in the window that opens uncheck the "copy items ... " option.
This will create a reference to your framework build file and not a copy.

Problems when adding an external framework in iOS

I want to add the PLCrashFramework in my app. This frameworks deals with crash reporting for iOS/MAC applications. What I did
Downloaded and unzipped the .zip file from the URL I have already provided.
In Xcode "Build Phases" -> Link Binary With Libraries
From the pop up "Choose frameworks and libraries to add"
Select "Add Other"... and select "CrashReporter.framework" and Open
After those steps I successfully built the project without problems.
I closed the Xcode, opened it again and tried to build. The build failed with
"header file not found", referring to a header file that belongs to the framework.
Why the xcode 6 does not find the header after closing and reopening the project?
Check your Framework Search Paths and Library Search Paths in your project's Build Settings. Check if you have a space in your directory structure. It's probably looking for 2 folders, one with the first part of the folder structure and one with the second. To fix this, simply add quotes around the whole folder structure.
You should add the framework though add file in project navigator by right click and select add file in your project and than browse to framework location and add framework. Remember to check copy file in your project it is must do. In this way Xcode will manage library header search path. You can see the framework will be added in Xcode "Build Phases" -> Link Binary With Libraries. If it is somehow not there you can add it by dragging framework from project navigator. The error will be gone.

How to change workspace name in Xcode?

Is there any appropriate way to change workspace name in Xcode?
Seems to me that it works to quit Xcode and manually change the .xcworkspace file from OLD_NAME.xcworkspace to NEW_NAME.xcworkspace.
Xcode 5 was used at the time of writing.
2019:
First note that this question is about changing the name of an Xcode workspace. The QA is not about changing the name of a project, a project within a workspace, the source folder, or other aspects of naming in the Xcode milieu.
Xcode 11 and further.
Surprisingly, you can now just change the name of the file ! As strange as that seems.
Quit Xcode. You must do this first.
Using your mouse, and keyboard, change the name:
This causes no problem with Swift Package Manager or any other issue.
You now simply open the .xcworkspace file as normal.
One part of a fifteen year old Apple problem resolved!
Steps to Rename Workspace
Rename the Folder( contain all files) of Main Project
Rename the Workspace
delete the Xcode project from Workspace and re-add/Drag Xcode project again to Workspace. And in build setting rename “product name”
Now, In Workspace ,select the project in general , option for selecting infoPlist will appear, select the info plist of project.
then, Click the Manage Scheme and Create New Scheme with Xcode Project Name , check the New Created Scheme and delete the older one.
clear the both Xcode and Workspace ..and delete Derived Data “~/Library/Developer/Xcode”
if project contain Bridging Header file then , just rename the Bridging Header file with With project name - “ProjectName-Bridging-Header.h” and then open the Xcode project not workspace. In build settings.. in “Swift Compiler -Code Generation”—> Objective-C Bridging Header — “reset the Path of Bridging header file”. close the Xocde. And if Project Contain Pod File , then open Pod file rename the target name with new project .close both xocde project and Workspace project and install the pod.
now open the Workspace clean and build.
Yeah I reckon so. As far as I can see, a workspace is just a reference to one or more Xcode projects and doesn't produce anything outside of those projects.
I tried the same (XC6) but got a build error with one file not found. Not a huge issue, but for some it might not be worth the effort.
In my case I had to rename also the project inside the workspace which had the same name.
For that it was important before renaming the project to..
close Xcode
rename the .xcworkspace-file from the Finder
open Xcode with new named workspace
rename the project inside the
workspace with Xcode help by clicking on the project name
I want to change the workspace name, project name and all linked file with old project name, so I tried the steps from this post, and it's really helpful
Renaming an Xcode project with Pods: the easy way
https://medium.com/programming-lite/renaming-an-xcode-9-project-with-pods-the-easy-way-5d1228ef25a

Add project dependencies in Xcode

I am working with the AR Drone to develop new application.
I want to establish a dependency between two projects. So when I compile one, I hope Xcode will help compile the another one automatically. I had searched with Google for this question. The solutions found are quite old and not applicable for Xcode 4.
Right now, I have two project, namely, ARDroneEngine.xcodeproj and FreeFlight.xcodeproj.
ARDroneEngine is a library for FreeFlight. Here comes the screenshot.
If I compile FreeFlight with iPhone / iPad simulator, it is fine since the ARDroneEngine is last compiled with the same setting. This is where the question lies. To test my application, I want to compile and run FreeFlight in my iPhone. So when I change the setting to "FreeFlight > xxx's iPhone" and compile, the error occurs: "Apple Mach-O Linker Error".
I think the problem is rooted from the Target Dependencies between two projects.
A quick workaround will be: Compile the ARDroneEngine again with the new Scheme "ARDroneEngine > xxx's iPhone" and launch FreeFlight in Xcode for my iPhone.
But I want a more complete solution with the dependencies between projects. If more information is required to solve the problem, I can always provide new info.
Thanks,
Steven
Xcode's solution to cases like this is to use a Workspace that encompasses both projects: then, when one project has a target that references the build product of another, it automagically works out the dependencies and builds them in order.
Create a new Workspace (File > New > Workspace); name it and save it anywhere you like (though putting it in a parent folder to both project directories might be a good idea).
Add both projects (drag the xcodeproj files from the Finder into the navigator pane, or use File > Add Files).
Expand the Products group of your library project so you can see the (placeholder for the) built library (libARDroneEngine.a).
Select the app project (FreeFlight) in the navigator and its app target in the editor -- you should be looking at the Summary pane for the target (the one with bundle identifier, deployment info, entitlements, and most importantly, the "Linked Frameworks & Libraries" list).
Drag the library (libARDroneEngine.a) from the navigator (where you made it visible in step 3) into the Linked Frameworks & Libraries list.
That's it! Now you can choose the FreeFlight > xxx scheme and it'll automatically build the library project before building the app.
You can probably get a more complete summary of these instructions (with screenshots and all) in the Xcode help for Workspaces.

How to update a framework in an iOS app?

I'm writing an app using Nuance's SpeechKit framework. I've just downloaded a newer version of the framework that contains new methods in some of the classes. To upgrade, I deleted the framework and the re-added the new one. When I right-click on the framework in Xcode and click "reveal in finder", it shows the new framework. When I open up the "Headers" subfolder of the framework in Xcode, I see the new methods.
The problem is that my class seems to still be referencing the header file in the old location, as the new methods are not visible within my application.
How do I upgrade a framework properly? Is there somewhere else in Xcode that contains a path reference to the SDK?
You need to delete Derived Data for the project - it is an option of the project in the XCode Organizer, on the projects tab. It will remove the cached build of the framework, forcing XCode to use the new one.
Choose Window/Organizer from the top menu
Click "Projects" pseudo-tab-thing, along the top of organizer window (icon looks like an XCode project file"
Select the project from the list on the left
Click "Delete" next to "Derived Data" in the area immediately below the project info header.
List item
EDIT: as of XCode 12 (should work with Xcode 8 and above), you can delete derived data like this:
Go to File > Workspace Settings if you are in a workspace environment or File > Project Settings for a regular project environment.
Then click over the little grey arrow under Derived data section and select your project folder to delete it in Finder.
I found what cause this issue for us.
When you build a new version you must update "Current Library Version".
There is also a "Compatibility Version"
In Xcode selector your framework target and in build settings search for linking and you will se this setting there.
We created a build script to bump this version number every time we build.
Xcode caches the frameworks and uses the cache if possible. That's why you need to change this number.
If you are using CocoaPods, run pod update [PODNAME].

Resources