class method inheritance problem with swift

So, I've had this problem with swift since day 01. I've mentioned it a few times in these forums,a nd I haven't been able to get a satisfactory answer.


there's a lot of details, but it resolves to this:

a subclass, that overrides a superclass's method, never gets that overridden method called. Instead... The base class's method gets called.


earlier in the day, the subclass's method would be called just after launch of the debug, but following something I haven't tied down yet, the base class's method gets called.


So I have a base class : BKControlProps

it's got this method :

open func mouseDraggedBehavior(event : NSEvent, viewPt : CGPoint){}


now there is a successive list of subclasses:

BKControlProps

BKScrollerProps

BKGroupProps

BKListProps


ScrollerProps overrides that mouseDraggedBehavior method:

open override func mouseDraggedBehavior(event : NSEvent, viewPt : CGPoint){
        let minOffset : CGFloat = 0.0025
        
        switch scrollValue {
        case .none:
            break
        case .horiz:
            deltaAggregate += 2 / self.xWorkingLength * event.deltaX
            if abs(deltaAggregate) > minOffset{
                self.xScrollAmnt += deltaAggregate
                deltaAggregate = 0
            }
        case .vert:
            deltaAggregate += 2 / self.yWorkingLength * event.deltaY
            if abs(deltaAggregate) > minOffset{
                self.yScrollAmnt += deltaAggregate
                deltaAggregate = 0
            }
        }
    }



I have an instance of GroupProps, and an instance of ListProps. Niether one of them overrides the method in question.


when the method is called in the GroupProps class... the method override in ScrollerProps is the one that is called.

When the same method is called in the ListProps class... the method in the Base class is called. All of these classes are NSObject subclasses.


As I mentioned earlier, the behavior I am reporting is errattic at times. So it's a bug. It's a HUGE bug by my accounting. What I am wondering now... is how I control it? if inheritence is busted, there seems to be some kind of trigger. what is it? how do I avoid it?

I cannot explain what goes on here.


But, to try understand, could you try to add in BKListProps


open func mouseDraggedBehavior(event : NSEvent, viewPt : CGPoint){
     super.mouseDraggedBehavior(event : event, viewPt : viewPt)
}

I’m not sure what’s going on here but from reading your post it’s clear that this happens as part of a much larger app. If you really want to get to the bottom of it my recommendation is that you extract the relevant bits from that large app into a small test app. This has two potential benefits:

  • At the end you’ll have a small test app that you can share with folks who are interested in this problem (and, if it comes to that, include in a bug report).

  • As you’re reduce the size of your test app you’ll get to a point where the problem stops occurring, and that’s an important clue in debugging it.

If you post a link to your test app’s project here I’m sure there’ll be more than one person who’d like to take a look (-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
class method inheritance problem with swift
 
 
Q