UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

2      

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"
  ...
}

3      

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.

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.