Handling app delegates and switching between views

前端 未结 3 1171
粉色の甜心
粉色の甜心 2020-12-07 10:52

I\'m getting a warning about a semantic issue pertaining to passing a *const _strong to type id and cannot seem to fix it no matter what I change.<

3条回答
  •  再見小時候
    2020-12-07 11:14

    This warning is oddly worded, but it is actually just a way of telling you that the class of self (whatever that class is) fails to conform to the ProductsViewControllerDelegate protocol. To get rid of the warning, you have two choices:

    • Declare the class of self (whatever that class is), in its @interface statement, to conform to the protocol ProductsViewControllerDelegate:

      @interface MyClass : NSObject ;
      
    • Suppress the warning by changing this:

      controller.delegate = self;
      

      to this:

      controller.delegate = (id)self;
      

    The delegate property is typed as id. But self is not. Under ARC you must make the cast explicit, so that the types formally agree. (I believe this is so that ARC can make absolutely certain it has sufficient information to make correct memory management decisions.)

提交回复
热议问题