Pyobjc indexed access method with range

I am trying to implement an indexed access method for my model class in Python, according to the KVC manual . I want to use an additional long-range method to load multiple objects at once for performance reasons. The method takes a pointer to the buffer of the C-array, which my method should copy to objects. I tried something like the following, which does not work. How to do it?

@objc.accessor    # i've also tried @objc.signature('v@:o^@')
def getFoos_range_(self, range):
    return self._some_array[range.location:range.location + range.length]

Change . Finally, I found the encoding type link after Apple moved all the documents. After reading this, I tried this:

@objc.signature('v@:N^@@')
def getFoos_range_(self, buf, range):

but that didn't work either. The first argument should be a pointer to a C-array, but the length is not known until runtime, so I did not know exactly how to build the correct type encoding. I tried 'v@:N^[1000@]@'just to look, and that didn't work either.

My model object is bound to the contentArray of the NSArrayController element that controls the table view. Apparently, he does not call this method at all, perhaps because he expects a different signature than the one the bridge provides. Any suggestions?

+3
source share
1 answer

You were close. The correct decorator for this method is:

@objc.signature('v@:o^@{_NSRange=QQ}')

NSRange , @; 1.

, . PyObjC , , , , , , . ( , , .)

objc.registerMetaDataForSelector:

objc.registerMetaDataForSelector(b"SUPERCLASSNAME", 
                                 b"getKey:range:",
        dict(retval=dict(type=objc._C_VOID),
             arguments={ 
                  2+0:  dict(type_modifier=objc._C_OUT,
                             c_array_length_in_arg=2+1),
                  2+1:  dict(type=b'{_NSRange=II}',
                             type64=b'{_NSRange=QQ}')
             }
        )
)

test_metadata_py.py ( test_metadata*.py ) PyObjC.

NB, , get<Key>:range: for, - ( , class, , , ). .

NSArray getObjects:range: Foundation PyObjC.bridgesupport 2 Apple BridgeSupport.

, , - ( , IMO):

@objc.signature('v@:o^@{_NSRange=QQ}')
def get<#Key#>_range_(self, buf, inRange):
    #NSLog(u"get<#Key#>")
    return self.<#Key#>.getObjects_range_(buf, inRange)

I.e., getObjects:range:.


1: 32- Python QQ, unsigned long long s, II, unsigned int s
2: ( Snow Leopard) :/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Foundation/PyObjC.bridgesupport

+2

All Articles