草庐IT

cocoa - 类不符合 Swift 中的 'CBPeripheralManagerDelegate'

我正在尝试在Swift中构建iBeacon发射器,但我无法让我的类采用CBPeripheralManagerDelegate协议(protocol)。在Objective-C中需要此协议(protocol)来初始化PeripheralManager对象,但在Swift中,我会收到以下错误:classMyBeacon:CBPeripheralManagerDelegate{//...}给出错误:'MyBeacon'doesnotconformto'CBPeripheralManagerDelegate'因为我的类没有采用协议(protocol),所以当我尝试使用自动完成初始化Periph

ios - 类型 '[T]'(数组类型)不符合协议(protocol)

让我用例子来解释这个问题。我有两个协议(protocol),名为-Mappable(在Git上可用)和Responsable(我创建了符合Mappable协议(protocol)的协议(protocol))protocolResponsable:Mappable{staticfuncgetResponse(map:Map)->Self}方法一然后我有结构'NSIResponse',它是通用的并且符合Mappable和通用T是Resposable类型structNSIResponse:MappablewhereT:Responsable{mutatingfuncmapping(map:M

ios - 参数类型不符合 Encodable

我正在尝试为POST请求创建结构。据我所知,该结构符合Codable类型别名,但我一直收到错误Argumenttype'RegisterUserRequest.Type'doesnotconformtoexpectedtype'Encodable'"whenpassingitinasaparametertomyJSONEncoder.我试图只遵循Encodable,编写建议的必需init(),但似乎没有任何效果。这是我的Struct的样子structRegisterUserRequest:Codable{varfirstName:StringvarlastName:Stringvare

升级win11提示“此电脑不符合安装windows11的最低系统要求”解决方法,适用所有电脑

稍微老一点的笔记本或者台式机在安装WIN11时会提示图片的内容。结合网上各种大神的办法,自己优化了一下在这里记录一下供大家参考。常规办法有两种,一种是按住shift+F10调出命令行,然后输入regedit命令打开注册表在当前界面按下快捷键Shift+F10,进入命令行窗口,并输入regedit,打开注册表,找到HKEY_LOCAL_MACHINE>SYSTEM>Setup这一项,并右键选择创建一个项,命名为LabConfig。右键LabConfig项,选择创建以下五个DWORD值:便可以继续安装了名称:BypassTPMCheck,值:0x00000001名称:BypassSecureBoo

swift - 为什么 [Int] 不符合 Swift 4.1 中的 Hashable?

使用Swift4.1(Xcode9.3)我试图创建一组[Int],但我得到:Type'[Int]'doesnotconformtotheprotocol'Hashable'但据我所知https://swift.org/blog/conditional-conformance/表示Array现在只要其值符合Hashable就符合Hashable。作为解决方法,我有:extensionArray:HashablewhereElement==Int{publicvarhashValue:Int{returndebugDescription.hashValue}}但我仍然想知道为什么我不免费获

ios - 参数类型 'String' 不符合预期类型 'Sequence'

我正在为ios开发一个应用程序,我正在尝试获取我定义的字典成员的每个字母:varMorse=["a":"01","b":"1000","c":"1010","d":"100","e":"0","f":"0010","g":"110","h":"0000","i":"00","j":"0111","k":"101","l":"0100","m":"11","n":"10","o":"111","p":"0110","q":"1101","r":"010","s":"000","t":"1","u":"001","v":"0001","w":"011","x":"1001","y":"10

swift - 此类不符合键名的键值编码。

这个问题在这里已经有了答案:Swift4"Thisclassisnotkeyvaluecodingcompliant"(1个回答)关闭5年前。我创建了一个名为Users的类,如下所示publicclassUsers:NSObject{varname:String?varemail:String?}和其他类创建用户类数组varregUser=[Users]()和funcfetchUser(){Database.database().reference().child("users").observe(.childAdded,with:{(DataSnapshot)inifletdicti

json - Int 不符合协议(protocol) 'StringLiteralConvertible'

我试图在天气应用程序中解析json,但遇到了一个我无法克服的障碍。我确实在以下代码中收到错误消息“Type'int'doesnotconformtoProtocol'StringLiteralConvertible'”。我尝试转换jsonResult["main"]但这确实给出了错误“后缀的操作数应该有可选类型,类型是AnyObject”。我是否需要以某种方式向下转换数组,如果是这样,我应该怎么做?我为此搜索了很多,但在其他帖子中找不到任何帮助。代码如下。funcupdateWeatherInfo(latitude:CLLocationDegrees,longitude:CLLocat

ios - 类型 'AnyObject' 不符合协议(protocol) 'Hashable'

我正在将现有的Objective-C项目转换为Swift。我正在转换一个出现上述错误的函数。请检查以下代码。objective-C-(IBAction)accessoryButtonTapped:(id)senderevent:(id)event{NSSet*touches=[eventallTouches];UITouch*touch=[touchesanyObject];CGPointcurrentTouchPosition=[touchlocationInView:self.tableView];NSIndexPath*indexPath=[self.tableViewindex

protocols - 类型 'className -> () -> className!' 不符合协议(protocol)

我在摆弄Swift。我有一个协议(protocol)定义为protocoltimerProtocol{functimerFired()}持有对委托(delegate)的引用的类classStopwatch:NSObject{vardelegate:protocolinit(delegate:protocol){self.delegate=delegate}...}和一个实现协议(protocol)的类classStopwatchesTableViewController:UITableViewController,timerProtocol{functimerFired(){print