Work with Frameworks in Swift - ios

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.

Related

Not able to access public swift class through framework

I created a project and imported it inside this framework. When i load this framework into a demo app, i am able to access the public class MyTest inside MyTest.swift file but not able to access the public class inside MessagesViewController.swift. Am i missing something? Can't we access files inside a project through a framework this way?
Restructure your project space so that you do not have your application inside your framework, then tackle linking files between the app and the framework.
Create a xcworkspace file to contain all of your sub-projects. For more information check out the Xcode Workspace section in the Xcode Concepts document
Open the workspace file and add your framework and app projects by dragging the xcodeproj files to the "Project Navigation" panel. Be careful when adding the files as Xcode as a tendency to place one project inside another, you don't want this.
Build your framework and then link it to the the app project. This will also make all you framework files available to your app project as long as they are public(see below for more details). Navigate to the FireChat-Swift app project target in the editor view then from the frameworks project open the product directory and drag the framework file to the Embedded Binaries section of the general tab.
Now your framework is linked with your app project. You will need to import your framework in your app's source code.
Add new files to your framework and remember they need to be public should you require them to be used outside of the framework - i.e. by your app.
Did you add MessagesViewController.swift to the Target inside the original Project?
To check it just open the original project, select MessagesViewController.swift and take a look at the right sidebar (Target Membership section).
I had this problem, and I fixed mine by going to my framework and adding target membership to Tests and UITests:
Strange fix, but I guess it works! 🤷‍♂️
This can also occur as part of a bug in Xcode, though I'm not sure what causes it - possibly dragging files from another project into your library. I just fixed this by closing down and restarting Xcode, then cleaning the build folder (hold down Alt then select the option from the Product menu).

How do I copy and rename/refactor ios xcode sample project as my starting point?

How do I copy one of the sample projects from developer.apple.com and use it as a starting point for my own app?
I have searched on-line, but cannot find an explanation of the necessary steps to rename/refactor an existing project.
First, copy the sample project and all files in its directory to a new directory and open the newly created .xcodeproj file in Xcode. Then edit the project file name in the project navigator on the left. Once you save a new name, Xcode will ask you if you want to rename related files and targets that share that name, which you do.
Now you want to edit your scheme, which is just to the right of the build button in the top left. Click on the scheme (which is likely the name of the sample project), and select manage schemes. Delete the scheme that has the old project name, and click Autocreate Schemes Now to create an appropriately named scheme for your project.
If you want to rename classes from the sample project, you can do this by right-clicking the class name in the code editor -> refactor -> rename. This will rename all uses of that class in your project along with it's .h and .m files. You can then remove any unneeded files from the sample project, and add any of your own files to the project.
Have a look at link below and follow the steps :
https://developer.apple.com/library/ios/qa/qa1625/_index.html

Using subproject's xcdatamodelId in main project

I have in XCode a main project that relies on a subproject to work. The subproject is basically a library that also define a database model, and the way to interact with it.
To use the subproject in the main project, I just dropped the subproject xcodeproj file in the main project, did some setup (like specifying header search path), and that's it.
I'm using core data, but if I try to use the .xcdatamodelId files directly, by creating managed object context, it fails : looks like the main project can't find the subproject ressources (except .h and .m files).
The only solution I found so far is to copy the .xcdatamodelId file from the subproject in the main project, and it does the trick. But it's not satisfactory, as I have to maintain two files if my model evolves.
I was struggling with this issue for a while and I want to answer it here as I believe it is important.
In order to add model files from a sub-project into the parent project you simply locate the model files you want to add in Finder. You can then drag them into your project into any folder you see fit. When Xcode displays the "Choose options for adding these files" prompt, deselect the "Copy items into destination group's folder" item and you can select either "Create Groups..." or "Create folder references...". After this process you should see the model files under the compile sources phase in Build Settings.
It is important to note that dragging the model files (in Xcode) from the sub-project into either "Compile Sources" or the parent project will not work to my knowledge so rather do it in Finder.

renaming classes in iOS

I am working on Xcode 4.3.2 i wanted to rename my classes so i used refactor>rename, but after that i changed my mind and decided to go back to the older name. But when i do the same thing i've done before again, a warning dialog appears saying:
yourclass.h is not part of the build phase of any targets in this workspace and so can't be refactored. add the file to the build phase of a target in this workspace, or make a selection in another file.
what's the build phase? how can i solve this problem?
Thank you very much
It may be worthwhile to delete the projects derived data
Organizer --> Projects --> hit the delete derived data button for the project in question
Quit XCode
Open XCode
Build project. This will re-index your project and has been known to fix various environment issues such as
code sense
auto complete and
copmpiler targets
In Xcode, select your project at the top of the file tree on the left hand side.
From there, select your target, and click the "Build Phases" tab. Make sure the .m file of the class you're wanting to rename is listed under "Compile Sources"
You could check if you have the file here:
Targets => Select the target which is the select target your scheme is trying to run => Tab Build Phases => Compile Sources
Check if there is something wrong there (like file in red).
xCode usually takes snapshots when you rename the classes through the re-factor option .. you can go to File > restore SnapShote .. and choose the snapshot you want retrieve to and you will get back all the changed names.
In my case the .m file was under the compile sources. I did clear the project derived data and restarted xcode but to no avail.
I figured out though, that attempting to refactor the specific property in the .m file worked and renamed the property both in the header and the rest of the project references.

XCode - Workspaces

i'm developing a framework and i would like to know if there is a method for share the code across multiple project. Example : i have my workspace with my framework project and a test application project for the fw; then, i have another project of an app and i need to use the framework, but i want to link the framework so that when i modify the original code in workspace even the code in the project is updated without import every time the .framework file.
Is it possible?
If not, how can i do to share code across projects?
Thanks
Yes, this can easily be done by importing files from the other project. You could create a group called external, right click and choose "add files". Make sure the option "copy items into destination group`s folder" is unchecked.
If you now change the files in the other project, the changes will be reflected in the dependent one.

Resources