pyobjc / Examples /

The branch 'pyobjc-ancient' does not exist.
# Demonstrates that the super-class implementation of an overridden method
# can be called in the same way as with normal objects.
# Well almost, the new 'super(MyClass, self).method(...)' convention is not
# supported yet because it looks directly into the __dict__ of classes, and
# that dict is empty for objective-C classes (well, until I find a way to work
# around a feature of Cocoa on MacOS X)
import objc

NSObject = objc.lookUpClass('NSObject')

N = 1

class MyObject (NSObject):
    def init(self):
        global N
        if N == 1:
            print "Calling super.init"
            N = 0

            # Call super-class implementation.
            super(MyObject, self).init()

            # The older convention also works:
            print "Cyclic call detected"

x = MyObject.alloc().init()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.