0

I have a shared delegate defined by a macro in an Objective-C class. I would like to access this shared delegate from a Swift class. I have defined my shared instance as:

#define APP_DELEGATE((AppDelegate *)[[UIApplication sharedApplication] delegate])

I have a property declared in my AppDelegate that I would like to access from my Swift class:

@property (nonatomic) BOOL isReady;

How would I accomplish this in Swift? Thanks in advance.

2
  • Possibly a duplicate of Convert Objective-C (#define) macro to Swift Commented Jan 8, 2016 at 21:54
  • 1
    create a function of some sort for that, or a stored property or whatever, dont use the macro. Commented Jan 8, 2016 at 21:55

1 Answer 1

3

This is a really bad design choice but you just simply create a function

func appDelegate() -> AppDelegate {
  return UIApplication.sharedApplication().delegate as! AppDelegate
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I did something similar. I just added a class method within my App Delegate and returned a shared instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.