草庐IT

ios - 如何覆盖子类的快速协议(protocol)函数(例如 UIView 的 UILabel)

我正在尝试实现一个扩展函数,该函数应该根据使用它的类的类型而有所不同。对象需要是UIView(或子类)。它应始终使用在指定类型上扩展的函数,但如果它不符合其中任何一个,则应改用UIView方法(作为后备)。这是我正在尝试做的一个例子:protocolaProtocol{typealiascompletionBlock=(_finished:Bool)->()funcdoSomething(completion:completionBlock)}extensionUIView:aProtocol{funcdoSomething(completion:(Bool)->()){print("

swift - 创建一个 Swift 字典子类?

我可以将SwiftDictionary子类化,以便我可以将我的自定义Dictionary传递给需要普通Dictionary?编辑Inmycase,IwantmycustomDictionarytoiteratethroughitskeysininsertion-order. 最佳答案 Swift字典是结构体,而不是类,因此它们不能被子类化。理想情况下,您正在使用的方法将被声明为采用适当约束的通用CollectionType(或ExtensibleCollectionType或SequenceType,视情况而定),而不是具体的字典。

swift - 创建一个 Swift 字典子类?

我可以将SwiftDictionary子类化,以便我可以将我的自定义Dictionary传递给需要普通Dictionary?编辑Inmycase,IwantmycustomDictionarytoiteratethroughitskeysininsertion-order. 最佳答案 Swift字典是结构体,而不是类,因此它们不能被子类化。理想情况下,您正在使用的方法将被声明为采用适当约束的通用CollectionType(或ExtensibleCollectionType或SequenceType,视情况而定),而不是具体的字典。

ios - 在子类中根据 UIButton 大小设置 cornerRadius 的最佳位置?

所以我将在应用程序中使用一些不同的圆形按钮(一直到圆形按钮),据我所知,实现此目的的最简单方法是设置按钮CALayer的cornerRadius属性。但是,我不想为每个Controller中需要它的每个按钮手动执行此操作,所以我认为在init上设置它的简单子(monad)类就是这种方式。我正在使用Storyboard和Autolayout来定位和调整按钮的大小,并将它们分配给这个子类。classRoundedButton:UIButton{requiredinit(coderaDecoder:NSCoder){super.init(coder:aDecoder)self.layer.c

ios - 在子类中根据 UIButton 大小设置 cornerRadius 的最佳位置?

所以我将在应用程序中使用一些不同的圆形按钮(一直到圆形按钮),据我所知,实现此目的的最简单方法是设置按钮CALayer的cornerRadius属性。但是,我不想为每个Controller中需要它的每个按钮手动执行此操作,所以我认为在init上设置它的简单子(monad)类就是这种方式。我正在使用Storyboard和Autolayout来定位和调整按钮的大小,并将它们分配给这个子类。classRoundedButton:UIButton{requiredinit(coderaDecoder:NSCoder){super.init(coder:aDecoder)self.layer.c

ios - 如何使用 swift 在 UIResponder 子类中将属性重新声明为可读写?

我正在尝试遵循本指南,但使用的是swift:InputAccessoryViewdockedatbottom我似乎无法为我的ViewController设置inputAccessoryView,根据文档,我需要重新声明它:Thevalueofthisread-onlypropertyisnil.Ifyouwanttoattachcustomcontrolstoasystem-suppliedinputview(suchasthesystemkeyboard)ortoacustominputview(oneyouprovideintheinputViewproperty),redecla

ios - 如何使用 swift 在 UIResponder 子类中将属性重新声明为可读写?

我正在尝试遵循本指南,但使用的是swift:InputAccessoryViewdockedatbottom我似乎无法为我的ViewController设置inputAccessoryView,根据文档,我需要重新声明它:Thevalueofthisread-onlypropertyisnil.Ifyouwanttoattachcustomcontrolstoasystem-suppliedinputview(suchasthesystemkeyboard)ortoacustominputview(oneyouprovideintheinputViewproperty),redecla

inheritance - swift 从其基类返回子类

我试图让父类(superclass)中的方法返回子类的实例,这样我就可以在父类和子类中使用方法链。但是,当我尝试链接方法时出现错误“BaseClass没有名为someOtherChainableMethod的成员”。这是我的代码:classBaseClass{funcsomeChainableMethod()->BaseClass{returnself}}classChildClass:BaseClass{funcsomeOtherChainableMethod()->ChildClass{returnself}}letchildClass=ChildClasschildClass.s

inheritance - swift 从其基类返回子类

我试图让父类(superclass)中的方法返回子类的实例,这样我就可以在父类和子类中使用方法链。但是,当我尝试链接方法时出现错误“BaseClass没有名为someOtherChainableMethod的成员”。这是我的代码:classBaseClass{funcsomeChainableMethod()->BaseClass{returnself}}classChildClass:BaseClass{funcsomeOtherChainableMethod()->ChildClass{returnself}}letchildClass=ChildClasschildClass.s

swift - 创建 NSManagedObject 子类...在我的项目中创建一个新错误

我想通过Editor\CreateNSManagedObjectSubclass...菜单为我的实体添加一个类。但是当我添加它时,项目出错了,这是消息:Multiplecommandsproduce'/Users/mohsenkhodadadzadeh/Library/Developer/Xcode/DerivedData/walk-fcnteanemrfigmfaalqkvwigvwqc/Build/Intermediates.noindex/walk.build/Debug-iphonesimulator/walk.build/Objects-normal/x86_64/WalkE