subclass

What is the difference between parent and base in Perl 5?

*爱你&永不变心* 提交于 2019-11-27 20:02:10
问题 There appears to be a new pragma named parent that does roughly the same thing as base. What does parent do that warrants a new (non-core) module? I am missing something? 回答1: base tried to do one too many things – automatically handling loading modules but also allowing establishing inheritance from classes already loaded (possibly from a file whose name wasn't based on the module name). To sort of make it work, there was some hackery that caused surprising results in some cases. Rather than

Create subclass with different subclass property

二次信任 提交于 2019-11-27 18:25:10
问题 Say I have this Class @interface CustomClass : NSObject @property (nonatomic, strong) NSArray * nicestArrayEver; @end And I want to create a subClass of CustomClass, but here is the catch @interface ASubClassCustomClass : CustomClass @property (nonatomic, strong) NSMutableArray * nicestArrayEver; @end The issue as you can imagine is that when I initialize ASubClassCustomClass and call it's super initializer (since there is other properties required) the inmutable nicestArrayEver is created..

How to properly implement the Equatable protocol in a class hierarchy?

◇◆丶佛笑我妖孽 提交于 2019-11-27 17:42:17
问题 I'm trying to implement the == operator (from Equatable ) in a base class and its subclasses in Swift 3. All of the classes will only be used in Swift so I do not want to involve NSObject or the NSCopying protocol. I started with a base class and a subclass: class Base { var x : Int } class Subclass : Base { var y : String } Now I wanted to add Equatable and the == operator to Base . Seems simple enough. Copy the == operator signature from the documentation: class Base : Equatable { var x :

How to subclass UIScrollView and make the delegate property private

寵の児 提交于 2019-11-27 17:13:34
Here is what I want to achieve: I want to subclass an UIScrollView to have additional functionality. This subclass should be able to react on scrolling, so i have to set the delegate property to self to receive events like: - (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView { ... } On the other hand, other classes should still be able to receive these events too, like they were using the base UIScrollView class. So I had different ideas how to solve that problem, but all of these are not entirely satisfying me :( My main approach is..using an own delegate property like this:

Swift - UIButton overriding setSelected

强颜欢笑 提交于 2019-11-27 17:12:59
问题 I'm making a UIButton subclass in Swift to perform custom drawing and animation on selection What would be the equivalent in Swift of overriding - (void)setSelected:(BOOL)selected in ObjC? I tried override var selected: Bool so I could implement an observer but I get Cannot override with a stored property 'selected' 回答1: Like others mentioned you can use willSet to detect changes. In an override, however, you do not need assign the value to super, you are just observing the existing change. A

Add rounded corners to all UIImageViews

﹥>﹥吖頭↗ 提交于 2019-11-27 17:01:06
I would like to add some rounded corners to all of the UIImageViews in my project. I have already got the code working, but am having to apply it to every image; should I subclass UIImageView to add this? If so, can someone give me some pointers as to how to do this? Here is the code - (void)viewDidLoad { [super viewDidLoad]; NSString *mainpath = [[NSBundle mainBundle] bundlePath]; welcomeImageView.image = [UIImage imageWithContentsOfFile:[mainpath stringByAppendingString:@"/test.png"]]; welcomeImageView.layer.cornerRadius = 9.0; welcomeImageView.layer.masksToBounds = YES; welcomeImageView

Call protected method from a subclass of another instance of different packages

白昼怎懂夜的黑 提交于 2019-11-27 16:55:12
问题 I want to invoke a protected method of another instance from within a subclass of the class providing this protected method. See the following example: public class Nano { protected void computeSize() { } } public class NanoContainer extends Nano { protected ArrayList<Nano> children; } public class SomeOtherNode extends NanoContainer { // {Nano} Overrides protected void computeSize() { for (Nano child: children) { child.computeSize(); // << computeSize() has protected access in nanolay.Nano }

some Numpy functions return ndarray instead of my subclass

て烟熏妆下的殇ゞ 提交于 2019-11-27 14:56:20
问题 I am subclassing Numpy's ndarray class, adding some meta-data and additional methods. I'm trying to follow the instructions in this article and that one. However, some Numpy (or Scipy) functions return the base class "ndarray" instead of my custom subclass. Other Numpy functions DO return my subclass, and I don't know what's the reason for the difference. How can I make all the numpy/scipy functions return my subclass? here's what I did: class Signal(np.ndarray): def __new__(cls, filename):

Call subclass's method from its superclass

*爱你&永不变心* 提交于 2019-11-27 14:46:48
I have two classes, named Parent and Child , as below. Parent is the superclass of Child I can call a method of the superclass from its subclass by using the keyword super . Is it possible to call a method of subclass from its superclass? Child.h #import <Foundation/Foundation.h> #import "Parent.h" @interface Child : Parent { } - (void) methodOfChild; @end Child.m #import "Child.h" @implementation Child - (void) methodOfChild { NSLog(@"I'm child"); } @end Parent.h: #import <Foundation/Foundation.h> @interface Parent : NSObject { } - (void) methodOfParent; @end Parent.m: #import "Parent.h"

Swift 3: subclassing NSObject or not?

笑着哭i 提交于 2019-11-27 14:08:33
I have read some posts like this one about the difference between subclassing NSObject in Swift or just having its native base class with no subclassing. But they all are a bit old posts, and I am not clear about this topic. When should you subclass NSObject ? What is the actual difference between subclassing it and not subclassing? What is currently the recommendation in Swift? mz2 Apple's documentation about NSObject states the following as an introduction: NSObject is the root class of most Objective-C class hierarchies. Through NSObject, objects inherit a basic interface to the runtime