草庐IT

nsobject

全部标签

objective-c - 在 Apple 的 NSObject 文档中, "receiver"的概念是什么?

我正在研究Swift中的面向对象编程,我认为NSObject是一个很好的起点,因为所有对象都继承自这个基类。在Apple'sdocumentationforNSObject,有些区域指的是“接收器”。“receiver”是指NSObject的实例吗? 最佳答案 它指的是Objective-c向对象“发送消息”的范例。在那个世界里,“方法”并不是真正的方法,它只是对象在说,“嘿,如果有人向我发送此消息(与该方法名称匹配的字符串),我会回复它。”即该对象是消息的“接收者”。所以是的,在您提到的文档中,NSObject是接收器,您看到的方

swift - Swift 4 中的 KVO 监听器问题

我正在使用ViewModel类,如果loginResponse变量有任何变化,我想设置观察者。@objcMembersclassViewModel:NSObject{varcount=300@objcdynamicvarloginResponse:Stringoverrideinit(){loginResponse="1"super.init()setupTimer()}funcsetupTimer(){_=Timer.scheduledTimer(timeInterval:1.0,target:self,selector:#selector(callTimer),userInfo:n

ios - 无法使用参数类型(productIdentifiers :Set<NSObject>))调用类型 SKproductsRequest 的初始值设定项

自从Swift2开始cannotinvokeinitializerfortypeSKproductsRequestwithanargumenttype(productIdentifiers:Set)对于我的NSSet中的应用内购买标识符if(SKPaymentQueue.canMakePayments()){letproductID:NSSet=NSSet(objects:"com.someurl.monthlyAutoRenewable","com.someurl.annualAutoRenewable")letrequest:SKProductsRequest=SKProducts

swift - 无法将 NSMutableDictionary 类型的值转换为预期的参数类型 '[NSObject:AnyObject]?'

我想将BarCodeReader添加到我的项目中,但我在尝试时遇到了一些问题。在这里我给出了错误代码,如何解决这个问题,请任何人帮助我解决这个问题。letdict=NSMutableDictionary()dict[NSLocalizedDescriptionKey]="Failedtoinitializetheapplication'ssaveddata"dict[NSLocalizedFailureReasonErrorKey]=failureReasondict[NSUnderlyingErrorKey]=errorerror=NSError(domain:"YOUR_ERROR

Swift 4 - 从类 'NSObject' 和 'UICollectionViewFlowLayout' 多重继承

我正在尝试以编程方式将集合单元格的大小设置为框架的宽度,但是,当我运行该应用程序时,单元格大小不会改变。这是调用Swift4和Xcode9的正确函数吗?importUIKitclassSettingsLauncher:NSObject,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewFlowLayout{letblackView=UIView()letcollectionView:UICollectionView={letlayout=UICollectionViewFlowLayout()letc

ios - swift 错误 : Value of type 'NSObject -> () ' AnimalListTableViewController' has no member 'tableView'

我正试图在swiftxcode中消除这些错误如果截图太小,这里是代码importUIKitclassAnimalListTableViewController:UITableViewController{overridefunctableView(tableView:UITableView,numberOfRowsInSectionsection:Int)->Int{return4}letindexPath=self.tableView.indexPathForSelectedRow()//thisiswheretheerrorappears,itsaysValueoftype'NSO

swift 2 : Cannot convert value of type '[NSObject : AnyObject]' to expected argument type '[String : AnyObject]'

我有一个用Swift1构建的项目。但是在自动转换为Swift2后,它显示错误:无法将类型'[NSObject:AnyObject]'的值转换为预期的参数类型'[String:AnyObject]'。函数代码:funccreateViewContainers()->NSDictionary{varcontainersDict=NSMutableDictionary()letitemsCount:Int=tabBar.items!.countasInt-1forindexin0...itemsCount{varviewContainer=createViewContainer()conta

ios - Swift - 动态转换类无条件?

我似乎不能将泛型类型转换为另一个类型?Swift抛出DynamicCastClassException。问题基本上是这样的://TisdefinedasT:NSObjectletoebj1=NetworkResponse()letoebj2=oebj1asNetworkResponse这就是我需要进行此转换的原因classBaseViewController:UIViewController{//NotallowedtomakeagenericviewControllerandthereforehavetocastthegenericdowntoNSObjectfuncfetchDat

Swift,NSObject 中的 CLLocationManagerDelegate 不起作用

我在使用CLLocationDelegate获取我的位置时遇到问题。我创建了UIView的新子类并且运行良好,但是当我创建NSObject的子类时,未调用CLLocationDelegate。我可以找到问题所在。这是我的代码:importUIKitimportCoreLocationclassLocationData:NSObject,CLLocationManagerDelegate{varlocationManager:CLLocationManager=CLLocationManager()overrideinit(){super.init()ifself.locationMan

ios - 何时在 Swift 中子类化 NSObject

我刚刚开始阅读有关Swift的内容。几年前曾经在这里和那里做objective-c,我有一个愚蠢的问题。在Swift中什么时候应该或不应该将NSObject子类化?有没有关于它的最佳实践?在Playground上,我可以这样做:publicclassPrinter{publicfuncSaySomething(s:String){print(s);}}varpr=Printer()pr.SaySomething("yo");一切都按预期工作。但是,我认为我可以通过创建CocoaTouchFramework来快速练习。所以我创建了Printer.swift,复制并粘贴了您在上面看到的类。