Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
113 views
in Technique[技术] by (71.8m points)

How to get sharedApplication in Swift on iOS?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

EDIT Swift 4.x

let app = UIApplication.shared.delegate as! AppDelegate

If you're e.g. not in a ViewController, you must:

import UIKit

Perhaps try:

let app = UIApplication.sharedApplication()

EDIT (Swift 3):

It should be noted that in Swift 3, to accomplish this, you will want to access the shared property instead:

let app = UIApplication.shared

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...