GeneCode
GeneCode

Reputation: 7588

Unable to assign delegate in global method

I have a singleton and in it I create a custom method that is going to be used by multiple viewcontrollers. The method is to display an email composer.

-(void)emailSend:(NSString*)bodyStr inVC:(UIViewController*)vc {

    if ([MFMailComposeViewController canSendMail]) {

        NSString *messageBody =  bodyStr;
        MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
        mc.mailComposeDelegate = vc; // <-- warning
        [mc setSubject:@"Say Hello"];
        [vc presentViewController:mc animated:YES completion:NULL];
    }else{

        // Not setup
    }

}

On other viewcontrollers I call this by:

[[MySingle singleton] emailSend:@"Testing" inVc:self];

The warning message is assigning to

id __Nullable from incompatible type UIViewController *__strong

Any way how to make it work?

Upvotes: 0

Views: 31

Answers (1)

KKRocks
KKRocks

Reputation: 8322

You need to make some changes on your method :

From :

-(void)emailSend:(NSString*)bodyStr inVC:(UIViewController*)vc 

To :

-(void)emailSend:(NSString*)bodyStr inVC:(id)vc 

Upvotes: 1

Related Questions