NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Where to put code for AppDelegate.swift when that file no longer exists in SwiftUI lifecycle?

Forums > SwiftUI

I'm trying to write a new App in SwiftUI that accesses a Parse database in MongoDB on Sashido that works for my old old App written in ObjC. I learned to use the Swift Package Manager to get the Swift Parse Package installed and updated (yay new learning). Now the instruction is to "update your custom API URL" with my applicationID, clientKey and server. From googling, those things need to go in the AppDelegate.swift file which no longer exists in SwiftUI.

I found some other interest in this topic appdelegate gone in SwiftUI

Does anyone know what the equivalent way in swiftui to do this would be?

from the documentation: Your AppDelegate.swift file should now look like this:

1 import UIKit
2 import ParseSwift

3 @main

etc

The documentation is old and Parse is pretty old... The advice I got from some sr. devs was try to get it to work with the existing database since we already have users and great data, but that I should probably start over and use Core Data and Cloudkit.

But I at least want to give getting my existing Parse stuff to work in SwiftUI a shot.

   

Question is, where in the AppDelegate it should go. From my understanding what I read here the variables(applicationID, clientKey and server) are Strings you need to call somewhere in your code? Can you use an enum for that?

enum MyStaticVariables {
  public static let applicationID = "sghsglskflkhl"
  ...
}

1      

If it the file no longer exists, why not create your own AppDelegate.swift file. In your folder / project structure it is typical to keep it close to your app, but that depends on your style for the project folder / file hierarchy. Then define the AppDelegate class, you can see the basic prinicple here.

In the class you will define your code for what you what the app to do (did it finishing loading, do you need to handle scenes, etc.)

Then add the AppDeletgate to application code.

1      

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.