Instantiation of objects in xib/cib

12 views
Skip to first unread message

Luke

unread,
Jan 20, 2023, 7:31:42 PM1/20/23
to Cappuccino & Objective-J
I've tried to put an Object in my xib file, with its Custom Class set to the correct name of a objj class in my code (for which there is of course a corresponding objc class that Xcode/IB can see, thanks to the objc .h/.m pair generation.  

I've done this before in prior objc projects, where I just want an object instance to be created for something like the backing NSArray (CPArray) store for an ArrayController, along with some delegate methods.  It's handy to have the xib loading mechanism look after the instantiation of this singleton instance rather than instantiating it in the main program code.  

However, is this supported in Cappuccino?

I'm getting the message "Cappuccino [info]: Unknown class "ResourcesFilesData" in cib file"
... followed of course by other failures of things sending messages to the object that was supposed to be instantiated. 

I note that the IB has some additional stuff in the Custom Class section, "Module" and "Inherit Module from Target" which I haven't set, but figured I didn't need so as the class picker did find the placeholder objc class (from the .h/.m pair generation for my .j file).  

Keary Suska

unread,
Jan 21, 2023, 12:51:02 PM1/21/23
to objec...@googlegroups.com
The nib2cib utility, which converts the xib files, has historically not been able to handle the “Custom Object” placeholder. You will have to use an alternate method. If the inter-object connectivity is complex enough it my be worthwhile to create a separate xib with your custom object as the owner.

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business”
> --
> You received this message because you are subscribed to the Google Groups "Cappuccino & Objective-J" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to objectivej+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/objectivej/57e69c77-7b86-4e6c-8f78-5eac08e63663n%40googlegroups.com.

Luke

unread,
Jan 21, 2023, 1:54:24 PM1/21/23
to Cappuccino & Objective-J
OK, thanks.

Martin Carlberg

unread,
Jan 23, 2023, 4:55:32 AM1/23/23
to Cappuccino & Objective-J
Hi Luke,

There is support for creating custom objects in the xib file. Make sure you import the .j file of the class file or the class will not be found when loading the cib. I use this all the time.

You can also set attributes on the created object at the User Defined Runtime Attributes in Xcode.

- Martin

Luke

unread,
Jan 23, 2023, 12:44:03 PM1/23/23
to Cappuccino & Objective-J

That's great news Martin.  I thought I was going to have to rip this out in favour of something much dumber.
Actually, I do have the relevant .j file for my 'custom class' included in the AppController.j, but I'm wondering if this is the right/only place it needs to be given your comment.  Where should the import statement(s) be?

Keary Suska

unread,
Jan 23, 2023, 3:10:12 PM1/23/23
to objec...@googlegroups.com
I am very curious as well, as it has never worked for me. Please post two you got it to work, if you are able to.

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business”



> To view this discussion on the web visit https://groups.google.com/d/msgid/objectivej/14d49c68-b469-4ba8-9be3-64474c397ac0n%40googlegroups.com.

Luke

unread,
Jan 23, 2023, 3:32:25 PM1/23/23
to Cappuccino & Objective-J
Actually, I just got the custom object loading satisfactorily.  I put an @import for the .j file containing the custom class in my AppController.j file, added the custom object to my xib with the correctly named custom class set.  

I'm pretty happy/excited about this as having this facility makes a huge difference on how you can neatly structure things (previously I was thinking that I'd have to jam loads of outlets in my AppController and do all sorts of gyrations to pass references to things to instances of various objects/controllers I would have to instantiate by hand). 

I'd imagine that it's probably a better idea to put the @import in main.j, rather than in the AppController.j file, and I note that the main.j file already has the AppController.j file @import, presumably for the same reason (to get the compiler to see the definitions that are also loaded in the cib).  I'll be trying that once I've cleaned up my code from various experiments.  

Martin Carlberg

unread,
Jan 24, 2023, 6:45:48 AM1/24/23
to Cappuccino & Objective-J
Hi Luke,

Great that you got it working. It can be, as you say, very convenient.

You can have the import in main.j or any other source file that is included in the import "chain" from main.j

- Martin

Reply all
Reply to author
Forward
0 new messages