我向我的某個類添加了自定義協議,並且在prepareForSegue:方法嘗試設置委託時收到編譯器警告。我得到的警告是...獲取警告爲自定義協議設置代理
Sending 'MyCustomViewControllerClass *const __strong' to parameter of incompatible type 'id<NSFileManagerDelegate>'
項目建立並運行,一切工作正常減去警告。如果我將<NSFileManagerDelegate>
添加到我的自定義課程中,警告消失。我錯過了什麼或者這是Xcode(6測試版)中的錯誤?該代碼是建立一個協議/代表,但我會反正它張貼標準代碼...
SomeSecondClass.h
#import <UIKit/UIKit>
@class SomeSecondCustomViewController;
@protocol SomeSecondCustomViewControllerDelegate <NSObject>
- (void)doThisForMe
@end
@interface SomeSecondCustomViewController : UIViewController
@property (weak, nonatomic) id <SomeSecondCustomViewControllerDelegate> delegate;
@end
SomeSecondClass.m
@interface SomeSecondViewController()
…stuff
-(void)someMethod {
[self.delegate doThisForMe];
}
@end
CustomClass.h
#import <UIKit/UIKit.h>
#import 「 SomeSecondViewController.h」
@interface MyCustomViewController : UIViewController <SomeSecondCustomViewControllerDelegate>
//adding on <NSFileManagerDelegate> removes the warning...
@end
CustomClass.h
...standard stuff...
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"MySegue"]) {
//this is where the warning happens on "self"
[segue.destinationViewController setDelegate:self];
}
}
- (void)doThisForMe {
//doing some stuff...
}
@end
我打開了以前的項目,其中警告不存在,現在出現相同的警告。我想知道這是否是Xcode問題?
僅供任何人瀏覽,這是Xcode 6中Swift兼容性的編譯器變更。向前移動Swift將期待設置代表的「as」類型。這與上述鑄造相同。我的猜測是這就是爲什麼警告只發生在Xcode 6中。 – DoS