我在應用程序委託中包含對應用程序使用過程中可能或可能不會創建的視圖的引用的工作片段。這個代碼只有在引用的對象存在後纔會被調用,所以不會崩潰。引用還不存在的對象
但是,編譯器檢測該基準,給予警告:
warning: Semantic Issue: Instance method
'-dismissPurchasingViewAndUpdateSetupView' not found (return type
defaults to 'id')
簡單地說,這是發生了什麼事:
在應用程序委託:
@interface appDelegate : NSObject
{
NSObject *purchasingView;
}
@property (nonatomic, retain) NSObject *purchasingView;
@end
@implementation appDelegate
@synthesize purchasingView;
-(void)aMethod
{
[purchasingView dismissPurchasingViewAndUpdateSetupView];
}
在視圖控制器:
-(void) someOtherMethod
{
//Let the app delegate know about the reference to this view
appDelegate *appDelegate = (appDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.purchasingView = self;
}
-(void)dismissPurchasingViewAndUpdateSetupView
{
[self dismissModalViewControllerAnimated:YES];
}
應用程序委託實現了SKPaymentTransactionObserver
,它接收由視圖控制器中的購買觸發的App Store通知。購買完成後,應用程序委託人通知視圖控制器自行解除它。
這是一個明智的方式來做到這一點?有沒有辦法讓編譯器忽略這樣的事實,即當應用程序第一次運行時,purchasingView
指針指向空?