草庐IT

Property

全部标签

swift - 使用多级属性在 RealmSwift 中创建 LinkingObjects 属性

根据Realmdocumentationforv0.102.0,这就是您创建反向关系的方式:人classPerson:Object{//...otherpropertydeclarationsletdogs=List()}狗(v1)classDog:Object{//...otherpropertydeclarationsletowners=LinkingObjects(fromType:Person.self,property:"dogs")}假设我们有另一个类,叫做DogFood,我们想创建一个叫做buyers的反向关系来跟踪Person的哪些实例有一只Dog吃掉DogFood的实

swift - 不符合协议(protocol)的属性(property)去哪儿了?

Teacher&TeamMate是两个协议(protocol)。Coach类符合这些协议(protocol)。protocolTeacher{varfirstName:String{get}varlastName:String{get}vartitle:String{get}}protocolTeamMate{varfirstName:String{get}funcrole()}classCoach:Teacher,TeamMate{varfirstName:StringvarlastName:Stringvartitle:Stringfuncrole(){print("coachth

swift - 如何在不使用内置撤消管理器的情况下撤消 NSManagedObject 删除?

我正在使用CoreData和NSUndoManager构建一个基于OSX文档的应用程序。我有一个全局NSUndoManager来处理撤消和重做,而不是使用每个NSManagedDocument中内置的默认值。这意味着我手动注册撤消和重做,而不是依赖它们在托管对象上下文更改时自动注册。当我从NSManagedObjectContext中删除NSManagedObject时,我想注册一个撤销来恢复被删除的对象。我知道这是可能的,因为默认情况下NSManagedDocument的内置NSUndoManager会执行此操作,但是在对象被删除后尝试使用该对象会引发错误。如何在撤消期间恢复实际对象

ios - Swift 属性观察不会覆盖

我编写了带有属性覆盖的类继承。我发现存储属性观察不像其他重写那样工作。这些类具有用于比较的存储属性和计算属性。classParent{varstoredProp:Int!{didSet{print("ParentstoredpropertydidSet")}}varcalcProp:Int{print("Parentcalculatedpropertyget")return100}}classChild:Parent{overridevarstoredProp:Int!{didSet{print("ChildstoredpropertydidSet")}}overridevarcalc

swift - 我们可以将 willSet 和 didSet 与 getter 和 setter 一起使用吗?

我正在阅读有关swift属性的willset和didset我开始知道我可以将它们与具有如下初始值的变量一起使用:varproperty="name"{willSet{print("propertyisabouttochanged")}didSet{ifproperty==oldValue{print("valuesaresame")}else{print("valuechanged")}}}property="anothername"我可以像下面这样使用willget和didset吗:varproperty2:String{willSet{print("valueisabouttoch

ios - TWTRTwitter sessionStore 现在返回 TWTRAuthSession : so how does one access the userName property now?

使用Swift中的TwitterKit3.3.0sharedInstance().sessionStore.session()现在返回一个TWTRAuthSession而不是TWTRSession,因为前。事情发生了变化,这很好,但是thedocumentation尚未更新以反射(reflect)这一点,因此我不再知道如何访问以前的TWTRSession对象提供的userName属性。 最佳答案 你可以用perform(_:)来做到这一点希望下面的内容能帮助那些面临这个问题的人。letusername=session.perform

Swift:将用户在 ABPersonViewController 中选择的信息复制到字典

我正在尝试实现funcpersonViewController(personViewController:ABPersonViewController!,shouldPerformDefaultActionForPersonperson:ABRecord!,propertyproperty:ABPropertyID,identifiervalueIdentifier:ABMultiValueIdentifier)->Bool函数,它是ABPersonViewControllerDelegate的一部分协议(protocol),每当用户点击ABPersonViewController中的

swift - 如何获取 Swift 4 中的类属性列表?

funcgetAllPropertyName(_aClass:AnyClass)->[String]{varcount=UInt32()letproperties=class_copyPropertyList(aClass,&count)varpropertyNames=[String]()letintCount=Int(count)foriin0..此代码在Swift3.2之前有效。但我使用的是Swift4,它给了我一个空的Array[String]。 最佳答案 您可以获得如下所示的属性:classClassTest{varpro

swift - 为什么子协议(protocol)不符合其父协议(protocol)?

这个问题在这里已经有了答案:Whycan'taget-onlypropertyrequirementinaprotocolbesatisfiedbyapropertywhichconforms?(3个答案)关闭3年前。我有符合协议(protocol)的结构,但使用的是派生协议(protocol),而不是直接使用其父协议(protocol):protocolA{}protocolB:A{}protocolC{varproperty:A{get}}structFoo:C{letproperty:A}structBar:C{letproperty:B}//Error:Type'Bar'doe

ios - 为 Swift 属性赋值

什么时候应该在swift中为属性赋值?有什么区别classThing{varsomething:String="CoolThing"}还有这个classThing{varsomething:Stringinit(){something="CoolThing"}}实际上,在init()上赋值时很明显,但是在使用第一段代码时何时赋值,哪种方法是正确的? 最佳答案 它们是相同的,但出于风格原因,Apple建议使用默认属性值模式“如果属性始终采用相同的初始值”。请参阅TheSwiftProgrammingLanguage:Initializ