Importing Appdelegate

importing AppDelegate

Is this the the correct way for accessing these variables or should I
be doing something differently?

You'll find that different people have different opinions about this. The style that I prefer is to have the app delegate pass the necessary information to the first view controller, and have that view controller pass it on to whatever view controllers it creates, and so on. The main reason for this is that it prevents child view controllers from depending on things that they have no business knowing about.

If you have some detail editor, for example, you want to be able to pass that editor exactly what it needs to do its work. If you give it that information, the editor is completely flexible -- it'll edit any information that you give it. If the editor knows that it should get its data from some external object, like the app delegate, then it loses some degree of flexibility -- it can only get data from the thing that it knows about.

So, it's fine to set up your data model in the app delegate. But when it comes to providing access to the model, think: tell, don't ask. That is, have the app delegate tell the first view controller what model object to use, and have that controller tell the next one, and so on. If you have to ask, you have to know who to ask, and that's where the dependencies start heading in the wrong direction.

every time I import AppDelegate into a .m file to access these
variable's data I feel like I'm doing some wrong.

Trust that instinct. Think about why it feels wrong.

How to create AppDelegate to Third party Framework bridge file

Move the #import "DCPathButton.h" to your AppDelegate.m and add this instead in the .h: @class DCPathButton;

How I can get reference of Swift AppDelegate from objective c code

As Kie already said, you need to #import "<ProductModuleName>-Swift.h" in your Obj-C .m file to get all Swift classes. Here a sample project with what you need https://github.com/aminbenarieb/Researches/tree/master/Swift/Swift_ObjC.

Update:
If your can't see Swift files in Objective-C files, make sure you have the Objective-C bridging header, as follows in Apple Documentation:

Importing Objective-C into Swift

To import a set of Objective-C files in the same app target as your
Swift code, you rely on an Objective-C bridging header to expose those
files to Swift. Xcode offers to create this header file when you add a
Swift file to an existing Objective-C app, or an Objective-C file to
an existing Swift app.

How do you import something in appDelegate.m(Objective-C) into a Swift project?

So basically, I translate every Obj-C code into Swift and put everything into AppDelegate.swift. It is easy than I thought with auto completion, and it works just fine.



Related Topics



Leave a reply



Submit