So I'm new to Swift. I see it's a fast-moving language.
But so many tutorials I see have AppDelegate and SceneDelegate as standard init files, why don't I have any? Why can't I seem to find an option for them?
The tutorials include one from July 2020 so I'm guessing this is some sort of recent update. How should I approach the two types of apps with different file types? As a "Veteran" programmer, which is more advantageous?
Thanks everyone. Happy Coding.
When creating a new iOS app, if you select SwiftUI App for the life cycle, this replaces the use of AppDelegate and SceneDelegate.
If you want a classic lifecycle delegate, you can select UIKit App Delegate instead.
The only way I know to get the result you did is to choose "SwiftUI" for Interface and "SwiftUI App" for Life Cycle in the New Project dialog. If you choose "Storyboard" for Interface, or "UIKit App Delegate" for Life Cycle, you will get the files you expected.
Related
Is there a way to enable an app to use the CoreData framework if the box "use CoreData" was not checked?
I know it could be done by altering AppDelegate.swift but I am trying to find a way to do it automatically
Checking the box "use CoreData" just causes Xcode to generate some boilerplate CoreData code for you (a persistentContainer property and a saveContext() method) and dump it into your AppDelegate. It doesn't need to go in AppDelegate, however, and you can certainly write or import your own persistent container into your app (and frankly, you should).
Checking the box also creates an empty CoreData .xcdatamodeld file to get you started with adding your own entities. Something you can just add yourself at any time.
So if by "automatically" you mean can you add couple files to your app to give you the equivalent code of checking the "use CoreData" box, then the answer is yes.
And you should hunt around for good CoreData swift boilerplate code that fits with the needs of your app. Apple's is just to get you started, and they rudely dump it into your AppDelegate rather than isolating it into a separate singleton, just to simplify for people just getting started with it.
This seems like a basic request, but I can't find the answer to it anywhere. I want to wrap some existing iOS code that I wrote, in a Appcelerator module. That's it. Important points:
I am NOT wrapping a pre-existing 3rd party iOS SDK.
I wrote the iOS code being wrapped.
Code is verified as working within xcode.
There are no .a files. There are 2x .h files and 2x .m files though.
There are no UI elements in the iOS code as it is only designed to connect the native bluetooth hardware to the app.
I have created a generic appcelerator iOS module project, built it, and successfully called the generic ID function within my app.
I cannot figure out how to successfully edit the generic module so that it utilizes my code. Every attempt results in it refusing to compile, and it's maddening.
I do not have access to Hyperloop.
Once I can successfully build the wrapped module, I would call an initialization function which triggers a native bluetooth hardware search. Once connected, there are functions within the module to send commands to the hardware and receive data back. This is the official documentation I've followed so far:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Quick_Start
That helped me build the blank module, include it in the app, and ensure that it worked by calling the built in test property. From there it stops short of actually telling me what I need to know. These are the closest things I've found so far, while still not being what I need:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Project-section-43288810_iOSModuleProject-AddaThird-PartyFramework
appcelerator module for existing ios project sdk
Heck, I still don't even know if I can do this within studio or if I have to edit the generic module in Xcode. Help! :) Many thanks in advance.
so first of all, this is not best practice and will cause possible problems in the future when the SDK changes and your module still relies on outdated core API's.
Regarding your question, you could either create a new component that subclasses the existing class, e.g.
class TiMyModuleListViewProxy : TiUiListViewProxy {
}
and call it with
var myList = MyModule.createListView();
or you write a category to extend the existing API with your own logic, e.g.
#interface TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value;
#end
#implementation TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value
{
// Set the value of "somethingElse" now
}
#end
I would prefer the second option since it matches a better Objective-C code-style, but please still be aware of the possible core-changes that might effect your implementation in the feature. Thanks!
I use a framework to share common code between my main application and a Today Extension. I frequently run into scenarios where I am attempting to access UIApplication.sharedApplication() (the main application singleton) that is running from my framework, to show alerts, open URLs, show image pickers, show spin selectors, etc.
As a temporary solution I have a global variable in the framework that I set to the UIApplication when the application starts, then the framework relies on that variable. This method feels wrong to me and I would love to know of a better solution.
What is the best practice for accessing the UIApplication singleton from my framework?
Most likely you are missing the following import statement:
#import <UIKit/UIKit.h>
If you can build your framework, when it uses UIApplication.sharedApplication(), it is good solution as far as I can see than saving UIApplication.sharedApplication() in some variable.
For a project I need to integrate Unity3d in an existing app I know Unity acts as a UIApplicationDelegate. I found an interesting article about this topic but it is not really clear to me how I can resolve my problems this way. Is it possible restart the delegation process from a ViewController? So when I switch to a viewController from my delegate and I want to navigate back then initialize the UIApplicationDelegate again?
Article I found:
http://alexanderwong.me/post/29949258838/building-a-ios-unity-uiview-uiviewcontroller
Thanks in advance
Have you tried using Unity to build a "standard" Unity iOS application, then integrating your existing code into that?
When you build for iOS from Unity, Unity will automatically stick a hook in your Application Delegate, in the following method:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
You can do other stuff in there, but down the bottom you should see the important line:
[self startUnity:application];
So what you can do is just take that line out of the didFinishLaunching method and put it ... wherever you want. You'll also want to keep a reference to the UIWindow* Unity draws to in your application delegate, so you can switch in and out of it as you please.
So, I'm not completely clear about exactly the things you want to do, but I definitely recommend as a first step you start with an integrated Unity build and work from there, or at least use it as a map if you want to roll your own implementation.
Its been a while, but better late then never ;)
You can not "restart" the delegation stuff. The UnityAppController is an AppDelegate, not a ViewController.
But you can decide when unity is started the first time. After that, unity is running and you have to either use the applicationDidEnterBackground call in the UnityAppController (for pre Unity 5) or just call setPause:true (using Unity 5) which stops the unity render loop. Just dont forget to reactivate it once you navigate back to the UnityViewController.
For the "how to start unity when u want to": Either subclass UnityAppController and override startUnity:(UIApplication*) application with an empty implementation. Then you call [super startUnity..] once you want to activate it.
The other way is not to subclass but create your own UnityAppController object and call all the methods (applicationDidFinsishLaunching etc.). Then you just wait with the initialization till you need unity for the first time. But i would recommend the first option.
You can also look here for a more detailed Description how i did it: http://www.markuszancolo.at/2014/05/integrating-unity-into-a-native-ios-app
To support iCloud, we're encouraged to use a UIDocument subclass. If I define a new subclass, set the project target version to 3.0, and test using for iOS 5 before using my new subclass, will the code work on iOS 4 or does linking in a subclass break backwards compatibility?
UIKit can be weak-linked, but the results would be undefined if you tried to initialize a UIDocument or UIDocument subclass. You would need something like:
if (NSStringFromClass(#"UIDocument"))
{
...
}
That would make it totally useless for your purposes. So the answer to your question is no, any code involving UIDocument would not run, but you could put conditional checks around such code. You're better off finding an alternative method for saving data.
It will need to link with UIDocument in order to understand what subclassing UIDocument actually means. For example, if you have class Bar which subclasses Foo, and Foo has method 'doBaz', you can call 'doBaz' on a Bar instance, but if the linker doesn't know Foo, it doesn't know Bar can doBaz.
You may be able to do a weak link though. There was a similar situation when iOS 4 came out, with iAds not being available in iOS 3, which was the best on iPad at the time.