Referencing Classes from Different Targets in xCode for iPhone Unit Testing - iphone

I am trying to unit test my iPhone application. I have created a new target and called it "LogicTests". But now I need to use a class called "Spaceship" inside the test. How can I do that?
UPDATE 1:
I made the Spaceship.m available to the unit testing target and that particular error was gone. Now I have different problem. The Spaceship.m file reference to the Cocos2d library. How can I add a reference to the Cocos2d library in the unit testing target. I tried right clicking the Link binary with libraries option and then adding the cocos2d framework but it gave me 153 errors or something.

To include it in that target, click on Spaceship.m, get the file's Info (Command-I), and make sure "LogicTests" is checked under the Target tab.
Beyond that, make sure you add
#import "Spaceship.h"
To the top of the particular test class. Good luck!

In Xcode 4 you press: Alt-Command-1 and then check that "LogicTests" is checked under the Target Membership tab.

Related

AppClip easy way to target all needed files

I am building AppClip app based on existing project. My question is - Is there an easy way to target all files which my couple of screens are depending on?
For example
I need add OrderViewController to an AppClip. This screen depends from OrderViewModel. OrderViewModel depends from BaseViewModel and NetworkManager. And so on, and so on, and so on...
By "depends from" I mean File_A using inside code from File_B. And to compile a target with File_A I need to include File_B too, to a target. And as you can imagine there might be a lot of dependency files. But I am lazy. And looking for some magic ;)
You can add the files you need (OrderViewController, OrderViewModel, NetworkManager ...etc ) in your targets like the Main app and the app clip like that
then define the custom compilation conditions with any name you like in my case I made it
APPCLIP
after that use (compiler directives) to differentiate between the main app and app clip like that
#if !APPCLIP
extension AppDelegate:MessagingDelegate{
}
#endif
in the main app, I use MessagingDelegate but in the app clip I don't so, I write a case to check if the app is running app clip or main app
here are some resources that could help you
https://needone.app/compiler-directives-in-swift/
https://betterprogramming.pub/how-to-build-an-app-clip-on-ios-14-a5045fd68eb4
https://medium.com/swlh/ios-14-app-clips-95bfaf2b159c

Xcode 4.2 is missing a .xib file?

So I'm pretty new to programming, so I downloaded Xcode 4.2 and got to work. I watched many online tutorials and the main problem I was having was that all the tutorials were for Xcode 4 and not 4.2, meaning when you chose empty application setting, it was missing the .xib file. So I found a tutorial on how to create a .xib file. I got through it all except for one step, and that was to drag the from the window outlet of the xAppdelegate to the window. I've tried this over and over, but it doesn't work.
Here is the tutorial if anyone needs to see it http://www.trappers.tk/site/2011/06/16/mainwindow-xib/
Please someone help me!
You need to hold Ctrl while dragging, else it will not work.
Guide.
As you Control-drag from an object to your source code, Interface Builder indicates where a new binding is valid. After you’ve made the connection, Xcode displays a dialog you use to configure the binding. You can use the dialog to configure all aspects of the binding.
Interface Builder uses the Xcode index to determine which key paths are valid, and can also discover what controller it should connect through—you can therefore connect from a user interface element such as a table column to a property in a model class header.
Check out the video here.
You should choose a SingleViewBased Application instead of Empty Application then study all files that how they connect with each other. You can choose Master Application also. They will help you.
see this Hello world Tutorial click me.
And Youtube is the best way to learning for beginners. Search tutorial video because action teach more than the text.

Cannot find window-based application on XCode

I am using XCode 4.2 and for some reason I cannot find the template for window-based application. Is there an extra step that I need to take here?
There is no longer a Window-based Application template starting from Xcode 4.2.
You have two other choices of "bare-bones" templates:
View-based Application template, which gives you a view on a storyboard to start with. It is similar to the one found in previous versions, except the view now resides on a storyboard which Xcode 4.2 makes use of.
Empty Application template, but you'll have to manually create and wire up a window nib file if you want to design your application in Interface Builder. It's nothing more than a trivial extra step, though.
If you can't make use of storyboards (e.g. to deploy to iOS 4 and earlier), you most likely need to go with the empty template. For the main window, just make a new Interface Builder file and assign it as your project target's Main Window.
Here are two very useful links:
The first one is a discussion on the Big Nerd Ranch forum where they discuss this issue - that the XCode 4.2 has done away with the Windows-template. They have a Template that you can use to add the "Windows-template" to your XCode installation. I have NOT tried this approach but you can try.
http://forums.bignerdranch.com/viewtopic.php?f=73&t=3336
As you dig through this thread - you will come on another site. This a blog post by Jeroen Trappers - on how to "manually" add the missing elements to an "Empty-application" template to make it "Window-template". I have followed these steps and they worked very well for me. In the process of going through these steps it does help you understand what is going on behind the scenes.Here is the URL to the post:
http://www.trappers.tk/site/2011/06/16/mainwindow-xib/
Window-based Application is now Empty Application. Just gives you an app delegate and a window. You build the rest.

Core-Plot: Unknown class CPLayerHostingView in Interface Builder file

Using core-plot does not seem to be an easy integration task. Header path are already setup. In Interface-Builder I create an CPLayerHostingView which belongs to a View Controller which is instantiated by Interface Builder.
When the nib file is loaded I get the message:
Unknown class CPLayerHostingView in Interface Builder file
I found, that there are two different versions of that object. One for Mac-Only called "CPLayerHostingView", one for iPhone only called "CPGraphHostingView".
If following the poplular example at http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application you would use the following lines, if building an iPhone-App:
CPGraphHostingView *graphView = (CPGraphHostingView*)self.view;
graphView.hostedGraph = graph;
http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
Here is the answer ..
U can see mars' answer there
"i got it to work....ok, i added the -all_load -ObjC flag in the Target>Settings....I think this is where everyone gets confused...There are 2 places where to put the other link and header search paths, in Project Settings and in Target Settings.."
So solution is
Add -all_load -ObjC in Project settings and target settings
I had to rename CPLayerHostingView to CPGraphHostingView to get this to work after upgrading to the latest version of core plot (along with iOS 4 and the upgrade of XCode).
I think you're saying that you get this error when you load the NIB file in your app's code. In that case, the error suggests that you haven't built the Core Plot classes into your application (iPhone) or linked against the CorePlot framework and copied into the app bundle's Frameworks/ directory (OS X).
CPGraphHostingView
thank u it worked for me aswell;
3 imp things
1>perform settings for both project target aswell as application target.(make sure configuration is all configuration)
2>give correct header search path for framework library
3>learn over it::::::-)
For whatever it is worth.
Followed tutorial: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application and ended up having that same error. I looked into the CorePlot framework folder and did not find that CPLayerHostingView there, but found CPGraphHostingView inside iPhoneOnly folder.
Changed CPLayerHostingView to CPGraphHostingView in IB and error disappeared.
So, check what is in yours and use it. May work.

Packaging a Bundle with a static library

I have a static library that includes some xibs. These will basically be the same across projects. I'd like to include the xibs as part of the library. I can include their veiwcontrollers, reference these controllers in the calling project but then there isn't a xib to load. When I right click the xib in the library project, it can't be part of the target.
I thought about creating a CFPluginBundle but that creates a new project. I'd loose all of my IBOutlet and IBAction references. What is the best way to reuse xibs that also have outlets and actions to specific controllers?
Here more discussion about it: Can you reference Xib files from static libraries on the iPhone?
I had the same problem when I wanted to export my project as a library for other developers to use.
I found the perfect solution to my view and it seems it will answer yours too.
There is an xcode plugin that allows you to build your project as a library which includes the resources as well.
https://github.com/kstenerud/iOS-Universal-Framework
I do not know the guys that built this plugin, but it works like a charm
I'm not sure what you mean by "include the xibs as part of the library", since static libraries can't have resources--but they also aren't shipped stand-alone, so they don't need to. If you just want code re-use for your own projects, you could keep the xibs where-ever you keep the static library, and just include the xibs in any project that uses the library.
If you go the CFPluginBundle route, you can make new bundle targets in an existing project; there's nothing magic about the templates, they just take care of making dummy files and turning on the right build settings. You can copy those into a new target in your existing project and it will work just fine. That said, I'm not sure what you mean about losing IBOutlet and IBAction references, since that information is part of the xib (and the class you are using in the xib), not the project.