How to create a global import to use in all the app? - swift

I would like to find a way to import a pods / library once and not into all the classes in my app

Use this above the app delegate class or anywhere but it is better to put it above app delegate class.
#_exported import LibraryName

Related

What is the differnce between #main and #uiapplicationmain

I need help understanding when to use #main vs #uiapplicationmain.
From what I know, #uiapplicationmain is an easier way of calling the uiapplicationmain(:::) where the class that is made after #uiapplicationmain is used as the App Delegate. I also know that it also creates an UIApplication.
I also know that app delegate becomes the entry point for the project.
From what I have read I was told that #main is also a entry point but it requires an main function.
What I want to know is what do they mean by the main entry point. Like what is Xcode doing to make it the "entry" point. And how does the whole #main thing work, as in how does it differ from #uiapplicationmain and what is it doing to the way Xcode runs the code.
All code has an entry point: the place where whoever calls that code actually calls. How does the whole program, comprising many Swift files, actually get started? We need an entry point for the whole program, which the runtime will call to launch us.
In Swift, this is the main.swift file. Its job is to call UIApplicationMain, which creates some instances including the app and the app delegate and gets the event loop running (and stays running for the rest of the time the app runs). A minimal main.swift file would have to look like this:
import UIKit
UIApplicationMain(
CommandLine.argc, CommandLine.unsafeArgv, nil,
NSStringFromClass(AppDelegate.self)
)
However, no one ever uses a main.swift file! It's boilerplate, so why bother? Instead, you say #main, and a main.swift file is generated for you behind the scenes. In particular, you put the attribute #main on your AppDelegate class, so the main.swift generator knows which class to instantiate as your application delegate.
Two more things to know:
Before Swift 5.3, #main was called #UIApplicationMain instead. From that point of view, they are identical, two names for the same thing.
New in Swift 5.3 and Xcode 12, you can designate one of your own types as #main and give it a static main function, where you do whatever you would have done in the main.swift file. That is something #UIApplicationMain cannot do:
#main
struct MyMain {
static func main() -> Void {
UIApplicationMain(
CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(AppDelegate.self)
)
}
}
#main is part of the new SwiftUI lifecycle, introduced in iOS 14.
#uiapplicationmain is the older version that's part of UISceneDelegate and UIApplicationDelegate, but is still in use. Both represent your app's lifecycle.

UIGestureRecognizer setState: in swift 3 [duplicate]

You can't write to self.state in the subclass unless you import UIGestureRecognizerSubclass.h as indicated here.
In a Swift environment, I'm confused how I'd go about importing this. I tried import UIGestureRecognizerSubclass.h, and without the .h, but I still can't write to self.state.
How would I accomplish this?
The Swift equivalent is simply:
import UIKit.UIGestureRecognizerSubclass
That imports the appropriate header.
You need to have or create a -Bridging-Header.h file to import objc headers such as the one you want. The import line looks like this:
#import <UIKit/UIGestureRecognizerSubclass.h>
If you don't already have a bridge header file in your app, the easiest way to get one is to add an objc class to your project, and xcode will ask if you want one, then creates the file and ties it into the settings for you. You can then delete the objc class.
Everything in that header file is automatically made available to your Swift code, no need to add any import lines in your swift files.

How can I use stage.scaleMode property in AS3 in class?

I only use classes. There is the "main" class of my app.
Code printscreen
That's right, you just forgot to import the StageScaleMode class:
import flash.display.StageScaleMode;

Why my import MessageUI in AppDelegate is not visible within my UITableViewController?

Since Swift files are visible for each others, why my import within Appelegate is not visible for one of my controllers? I get an error there.
This is called Access level for Swift Modules. Default access level for Swift modules is internal, that is to that file itself.
Have a look here in Apple documentation Access level in Swift module
You need to import frameworks/modules in which ever class you are using.
Put import MessageUI at the top of the file where you declare your PBOUserViewController class (which I hope is contained in a separate .swift file than your AppDelegate).

import classes with Swift iOS

I'm trying Swift and I'm having some troubles..
I have a TableViewController.swift and also a DataModel.swift but I don't know how to import DataModel class into TableViewController to use in it. I'm trying with
import DPBDataModel.swift
but it doesn't works (No such module)
Thanks for your replies!
Try just using your DataModel class into TableViewController without importing anything ;-)
We need not to import any class in swift like objective c
Simply instantiate your class & you can use it.