如何使协议(protocol)方法对实现该协议(protocol)的人显示为已弃用?我试过使用@available如下所示,但是在实现协议(protocol)方法时Xcode中没有显示任何警告。protocolTestDelegate{@available(*,deprecated,message:"Don'tusethisanymore")funcmyMethod()->Bool}extensionViewController:TestDelegate{funcmyMethod()->Bool{returntrue}} 最佳答案
假设有一个协议(protocol)Draggable,通常会被一个UIView对象符合protocolDraggable{drag()}我们可以在协议(protocol)扩展中实现drag()作为选项1//option1extensionDraggablewhereSelf:UIView{funcdrag(){//implementation}}extensionUIView:Draggable{}//addedafter@RichTolley'sanswer或者我们可以在UIView扩展中实现drag()作为选项2//option2extensionUIView:Draggable{
假设有一个协议(protocol)Draggable,通常会被一个UIView对象符合protocolDraggable{drag()}我们可以在协议(protocol)扩展中实现drag()作为选项1//option1extensionDraggablewhereSelf:UIView{funcdrag(){//implementation}}extensionUIView:Draggable{}//addedafter@RichTolley'sanswer或者我们可以在UIView扩展中实现drag()作为选项2//option2extensionUIView:Draggable{
我有一个Objective-C协议(protocol),我正试图在Swift类中实现它。例如:@classAnObjcClass;@protocolObjcProtocol-(void)somethingWithAnArgument:(AnObjcClass*)arg;@end当我尝试在这样的Swift类中遵循它时:@objcclassSwiftClass:NSObject,ObjcProtocol{//...}我收到以下可怕的编译器错误:Type"SwiftClass"cannotconformtoprotocol"ObjcProtocol"becauseithasrequireme
我有一个Objective-C协议(protocol),我正试图在Swift类中实现它。例如:@classAnObjcClass;@protocolObjcProtocol-(void)somethingWithAnArgument:(AnObjcClass*)arg;@end当我尝试在这样的Swift类中遵循它时:@objcclassSwiftClass:NSObject,ObjcProtocol{//...}我收到以下可怕的编译器错误:Type"SwiftClass"cannotconformtoprotocol"ObjcProtocol"becauseithasrequireme
我的iOS项目一直面临以下问题(这只是一个警告)。'Hashable.hashValue'isdeprecatedasaprotocolrequirement;conformtype'ActiveType'to'Hashable'byimplementing'hash(into:)'insteadXcode10.2swift5源代码:publicenumActiveType{casementioncasehashtagcaseurlcasecustom(pattern:String)varpattern:String{switchself{case.mention:returnRege
我的iOS项目一直面临以下问题(这只是一个警告)。'Hashable.hashValue'isdeprecatedasaprotocolrequirement;conformtype'ActiveType'to'Hashable'byimplementing'hash(into:)'insteadXcode10.2swift5源代码:publicenumActiveType{casementioncasehashtagcaseurlcasecustom(pattern:String)varpattern:String{switchself{case.mention:returnRege
我想在IB中连接一个自定义的swift委托(delegate)。delegate是swift中实现某种协议(protocol)的对象。protocolThumbnailTableViewCellDelegate{funccellWasTouched(thumbnail:Bool,cell:UITableViewCell)}classThumbnailTableViewCell:UITableViewCell{@IBOutletvarthumbnailTableViewCellDelegate:ThumbnailTableViewCellDelegate?}不幸的是,编译器会提示:err
我想在IB中连接一个自定义的swift委托(delegate)。delegate是swift中实现某种协议(protocol)的对象。protocolThumbnailTableViewCellDelegate{funccellWasTouched(thumbnail:Bool,cell:UITableViewCell)}classThumbnailTableViewCell:UITableViewCell{@IBOutletvarthumbnailTableViewCellDelegate:ThumbnailTableViewCellDelegate?}不幸的是,编译器会提示:err
在协议(protocol)扩展中实现返回Self的静态协议(protocol)函数时,在扩展中函数的实现中出现错误(显示没有上下文的最小简化场景):importFoundationprotocolP{staticfuncf()->Selfstaticfuncg()->Self}extensionP{staticfuncf()->Self{//Method'f()'innon-finalclass'NSData'mustreturn`Self`toconformtoprotocol'P'returng()}}extensionNSData:P{staticfuncg()->Self{re