Can't access class' parent's companion object - kotlin

In my class I'm referencing a utils object that holds some consts. That utils object inherits from a parent utils object that also has consts. In my class, I want to access the parent's companion consts via a reference to the child utils class. Is this possible?
EDIT
This isn't technically necessary (simply referencing the base class works in my specific case) but I'm still interested from a language perspective if this is possible.

Companion objects and their members can only be accessed via the containing class name, not via instances of the containing class. [...] If you try to redeclare a companion object in a subclass, you'll just shadow the one from the base class.
In other words: It's not possible, as both companion objects are completely unrelated.

Related

How to reference super class in constructor in kotlin

I have a class that extends a class, and implements an interface by delegation. However, when initializing the delegate object, I want to pass a protected property of the superclass. How can I access it? I've tried writing the property name by itself, and accessing super.property but neither works. Is it possible to do this?
You need to create the delegate object first and do your setup after the constructor of your class is done.
If the property you need to access is private or hidden, you will need some custom method to pass the property to the delegate.
Perhaps you might want to rethink your strategy for initialization, and consider a build pattern. Yet it would help us if you where to provide some sample code and explain more in detail.

Forward declaration in Objective-C in child class

In our project, we have a series of classes that used to work fine.
In Xcode 4.1's latest update the behaviour seems to have changed, highlighting an issue in our code that wasn't detected before.
Here's the situation, using example classes to narrow the problem down:
Class Child inherits from class Parent
Class Parent declares (.h) an ElementalObject (but doesn't make it a property, because it's supposed to be protected, as in only used in Parent and its children) where #class ElementalObject is used.
Class Parent assigns the ElementalObject (imported with #import) in the .m
Class Child calls a method on the ElementalObject through [theElementalObject doStuff];
An error is shown at this step:
**ARC semantic issue:**
Receiver type 'ElementalObject' for instance message is a forward declaration
Since the Child class does not redeclare, or reassign, theElementalObject, I do not see why it should contain an import to the ElementalObject header file, which is already imported in the Parent implementation file.
It seems, unless I'm also misunderstanding that, that the compiler tells me otherwise.
Could anyone clear this up?
You do need to import ElementalObject.h in the child class's .m.
While the child class is not declaring the property, nor assigning it, it is trying to call methods on it. Unless the header for ElementalObject is imported, it has no idea what methods theElementalObject responds to.
Basically, if you do anything with a class, you must import the .h somewhere for the .m that uses it.

In Objective-C, when are metaclass object and class object created?

In Objective-C, when are the class pairs - metaclass object and class object, created? Is it in the beginning of the app execution or at the point when you first instantiate the first object of a class?
At the point that the class is added to the class hierarchy. This is generally when the app is launched, but could be later if the class is added by a dynamically loaded library or is created programatically.
The class object and metaclass have to exist at the time that +load is called (which is the above).

Call a parent's method/property

I have a custom class and I add it as child of a scene. In this custom class, I'd like to call a method or property found in the scene. So basically how can I call methods/properties from
You can use CocosNode's get_ancestor(self, klass) routine to discover the objects that contain the node. If you specify the scene's class in the klass parameter, that routine should give you the object you're looking for.

Is it possible to call a method from the instantiating class?

I have a class that is derived of UITableViewController and handles everything related with a specific type of tables. Let's call it Class T
In may main application class, Class A, I have methods to populate other areas of the screen as, for instance, a map.
While I'm populating my table within Class T, I would like to call the Class A method that plots the x,y points on the map.
Is this possible? What should be the correct way to do this?
When I though about this approach, I was expecting that invoking [super ...] inside Class T would call the Class A methods, as this is the owner class of the instance, but ofcourse it call the parent class, in my case the UITableViewController.
Thank you,
Pedro
If A is your main application class, you should be able to access the application instance with [UIApplication sharedApplication], cast it to the class A type, and call the APIs you need to call.
Why not define a ClassAProtocol and then add a property "classADelegate" in Class T?
ClassAProtocol will define a method like:
-(void)plotXYOnMapFromData:(id)someObjectContainingDataToPlot;
So in the Class T interface you will add:
#property (assign) id classADelegate;
and then when you instantiate, let's say from instanceA (instance of Class A), instanceT (instance of Class T) you will do:
instanceT.classADelegate = instanceA;
Finally inside Class T you can call the plotting method in this way:
[classADelegate plotXYOnMapFromData:myDataToPlot];
The advantage of the delegate pattern in this case is that Class T just need to know only one small piece of ClassA, which is the protocol, and ClassA is able to communicate with T thanks to its implementation of the protocol.