Re: [Pyobjc-dev] NSString & mutability
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2003-02-05 17:12:13
|
On Wednesday, Feb 5, 2003, at 10:23 America/New_York, bb...@ma... wrote: > > What we really need is a way to attach the NSString instance to the > PythonString instance such that any crossing of the bridge can > directly grab the NSString on entry into ObjC. > > I have realized that I'm wrong in regards to avoiding conversion -- > conversion isn't the problem. The problem is the lack of preserving > the identity as a string crosses from Python to ObjC and back again. > That the developer will always have to access the NSString methods via > unbound methods is annoying, but not catastrophically so. > The method I proposed the other day, subclassing str (and converting on first entry from objc->python) and implementing a custom version of __new__ should solve (almost?) all of these problems... with the caveat that it takes more memory because it converts the string (perhaps only the first time across the bridge). It would certainly fill in for a python str in 99% of the places that a python str is accepted (because it's a subclass of str itself). You can also solve the NSString accessibility as well this way with the __getattr__ to the instance of the NSString it keeps around. Of course, you'd still need the ObjC class on the other side to accept Python strings.. which I think already works just fine? -bob |