Adriaan van Os via fpc-pascal
2021-03-27 18:11:38 UTC
The FPC PasCocoa/Differences wiki <https://wiki.lazarus.freepascal.org/FPC_PasCocoa/Differences>
writes about ObjC class extensions:
"You can use regular (non-external) categories defined in the implementation of a unit instead of
class extensions, as the effect will be the same."
However, the Apple Programming with Objective-C manual writes here
<https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html>
"Categories can be used to declare either instance methods or class methods but are not usually
suitable for declaring additional properties."
and
"The only way to add a traditional property—backed by a new instance variable—to an existing class
is to use a class extension, as described in Class Extensions Extend the Internal Implementation."
So, the FPC PasCocoa/Differences wiki seems to ignore a crucial difference between ObjC categories
and ObjC class extensions, namely the ability to add properties to an existing class.
Am I correct that the latter is not possible in Objective-Pascal ? So, for example, I want to add a
pointer field to NSView and all used classes inheriting from it. I could of course subclass NSView
and used the classes inheriting from it, but that would be rather clumsy.
Regards,
Adriaan van Os
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.f
writes about ObjC class extensions:
"You can use regular (non-external) categories defined in the implementation of a unit instead of
class extensions, as the effect will be the same."
However, the Apple Programming with Objective-C manual writes here
<https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html>
"Categories can be used to declare either instance methods or class methods but are not usually
suitable for declaring additional properties."
and
"The only way to add a traditional property—backed by a new instance variable—to an existing class
is to use a class extension, as described in Class Extensions Extend the Internal Implementation."
So, the FPC PasCocoa/Differences wiki seems to ignore a crucial difference between ObjC categories
and ObjC class extensions, namely the ability to add properties to an existing class.
Am I correct that the latter is not possible in Objective-Pascal ? So, for example, I want to add a
pointer field to NSView and all used classes inheriting from it. I could of course subclass NSView
and used the classes inheriting from it, but that would be rather clumsy.
Regards,
Adriaan van Os
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
https://lists.f