AppClip easy way to target all needed files - swift

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

Related

iPhone Finding AppDelegate

I am trying to create MAC application.
My input is --> Source Code Folder of an existing iPhone Application.
Using my application I want to insert an extra screen in the existing application. The extra screen will be always the first screen.
Since I want to Automate this, I have written a MAC application which browses through the Source code folder and replaces the first screen of app with my extra screen. This is working perfectly for Single View Application where I get the AppDelegate class name from the main.m file ( by parsing UIApplicationMain(argc,argv,MyAppDelegate,nil) ) line.
The application fails when the third argument is 'nil' in some of the applications (which may depend on the implementer or type of project).
Is it possible to make my application generic for all kind of applications?
Regards,
Nirav
Looks like you would only have to search (recursively) the folder for all .h files, and then detect the name of the class that implements UIApplicationDelegate. There should not usually have more than one, and would work with the defaults templates I guess.

iOS full/lite version using multiple windows

I have two targets in my Xcode 4.3 project. Each target has its own X-info.plist file. I would like to have two windows (MainWindow.xib), one for the full app and one for the Lite version. I set the Main Interface for each target and also Main nib file base name in the X-info.plist but it's not working. What did I miss?
Thx
You can add a Preprocessor Macro to the target of the lite version LITE=1. Then in your code, when you want to execute something differently you can use #ifdef, for example:
NSString *mainWindow;
#ifdef LITE
mainWindow = #"MainWindow_Lite";
#else
mainWindow = #"MainWindow_Full";
#endif
// Load nib with the name mainWindow.
// Or load ads in the lite version
// Or disable functionality in the lite version
//
If you want to avoid doing that and want to use the same name for the two nibs, you have to add one of them as a member of the full target and the other one as a member of the lite target.
You can easily have the even same names for .xib files for different targets. Just make sure that two files with the same name aren't members of the same target. They have to be placed in different directories on HD and in different groups in project.
There is also a known bug with IB (image resources and so on) and multiple targets: see more at Two targets with separate .xib (image resources with same names)
But this information is for XCode 4.2.x, not sure if it/s valid for XCode 4.3

Referencing Classes from Different Targets in xCode for iPhone Unit Testing

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.

One App, Multiple Branding

I have made an application for the iPhone but it is required to be released with multiple brandings. Eg Differernt:
App Name
Icons
Default.png
Text replaced for the app name in IB
Colour schemes for all images such as backgrounds, icons etc
I'm not sure of the best way to do this.
I was thinking of a plist file for each branding that would have the name of the files to load eg "brand1_background.png" for brand1 but that would get very messy with the text replacement. It would also mean that all brands images would be in the package making it of larger size.
Looking around a bit I could have an 'images' folder for each brand and drag it in to build that brand's app, however the text is still an issue.
I'm wondering how everyone else would handle this situation as I want to do it as right as possible.
There are 2 different aspects to this problem, which I'd describe as follows:
Stuff that can be changed dynamically
Stuff that can't be changed dynamically
The first category is super easy. If you have your colo(u)r schemes stored in some easily-readable format like a plist or whatever, you can just load up that file during app startup, and build UIColor objects from them and use those where appropriate. The same goes for images used within the app itself. This is not a hard problem.
The second category is trickier. This is stuff that has to be baked into the application because of code signing. This means that the things like the App Name, the icon, Default.png, etc, all have to be changed before the app is signed in the compilation process. So what I'd do is bake up a bunch of scripts to take your branding information (name, image files, icons, etc) and load it up, then generate your Info.plist file and whatnot. This should be done as one of the first phases of your compilation.
For what it's worth, I work on an application where we do exactly this process, and it works pretty well. It's a bit tedious to update when we change what resources get branded, but I'm not sure there's any decent way around that.
Create a target for each of your brandings. For each single target you can add different files (e.g. images) and set an app name. You can even use the same file names (but stored under a different location) and you can build your brand-apps pretty fast.

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.