Mihir Mehta
Mihir Mehta

Reputation: 13843

dispatch_get_main_queue() objc warning after Swift 3 conversion

I Convert my Objective C + Swift 2.x code to Swift 3 in Xcode 8. After converting the code i am getting these new warning that i don't know if it's safe ti ignore/how to resolve it.

My Swift 3 code :

func getUserNotificationFromServer(_ completionQueue:DispatchQueue = DispatchQueue.main,callback: @escaping (_ succeeded: Bool, _ response: AnyObject?) -> Void)  {

Objective C code that calls this function

 [wsManager getUserFavouritesFromServer:dispatch_get_main_queue() callback:^(BOOL succeeded, id  _Nullable response) {

Warning that i am receiving

Incompatible pointer types sending 'dispatch_queue_t _Nonnull' (aka 'NSObject *') to parameter of type 'OS_dispatch_queue * _Nonnull'

Any thoughts ?

Upvotes: 2

Views: 616

Answers (1)

OOPer
OOPer

Reputation: 47896

I don't understand why, but the DispatchQueue is exposed as OS_dispatch_queue * in the generated {ProjectModuleName}-Swift.h .

(Better send a bug report to Apple.)

As far as I tested, just casting as suggested in the message suppresses the warning, and the code works as expected:

[wsManager getUserNotificationFromServer:(OS_dispatch_queue * _Nonnull)dispatch_get_main_queue()
                                callback:^(BOOL succeeded, id  _Nullable response) {

Upvotes: 1

Related Questions