I am trying to make my first plugin completely in Objective-C. So far I got some things working that are all Apple Code related. Now I am trying to get the connection to Glyphs objects. How can I access the python equivalents to Glyphs.font aka Font, Font.glyphs and Font.selectedLayers? As soon as I can wrap my head around these, I might probably be able to puzzle other translations from the python documentation myself. Hopefully.
Edit:
I just found one way by climbing up the ladder via the parent attributes from the given Layer in the drawBackgroundForLayer: method. But I guess there is a more direct way?!
Okay, I could find my way by looking into the GlyphSILE.m by @SimonC – I also added what he called »// Horrible private things« But I can make it work. Thanks so far.
I want to get the position of a layer’s anchor. According to the documentation and the object wrapper, the GSAnchor doesn’t have a position property, but it inherits from GSElement (NSObject) which has one. So Xcode eats my .position call, but still the console logs -[NSTaggedPointerString position]: unrecognized selector sent to instance
But what when I use anchorsTraversingComponents ? It returns an array and I can NSLog the anchors in there like this GSAnchor <0x60000e283d40>: topright, {602, 740} but they still refuse to accept the position property.
That doesn’t work. But thanks anyway! I can access the anchor already as you see in my comment of the console log. It just refuses to return the name or position
@ecuk.name and .position are ObjectiveC properties and not struct members. You still could do thisAnchor->_name the access the underlying member variable but that would mess things up quite easily and the compiler would not allow it. (*thisAnchor).name doesn’t work as this only works for structs
@Mark how does it fail. On compilation or in runtime?
@Georg: when I wanted to answer your question, I found that the error message in the compiler actually told me what my problem was. I forward declared GSAnchor, so stupid me forgot to import GSAnchor. Shame on me, so sorry! I thought I get used to objective-c quite a bit (there’s some progress, you’ll see soon). But those little things are not yet second nature
btw: I’ll try to let my fingers off this funky arrow syntax with -> I had the impression you advised to try to avoid that.
Yes, my bad. The arrow syntax is used often in C but much less often in Objective-C. Like I said, my Objective-C skills have clearly decreased in the last few years. (I wrote an audio voice synthesis app for the iPad in Objective-C a few years ago, but otherwise my primary language for decades (eek, plural) has been C.) It was only after I sent my original message—too late at night, I fear—that I remembered the semantics of Objective-C properties and their getters and setters. So thank you, @GeorgSeifert, for correcting me (and for refreshing my failing memory).
It is always a good idea to read the error messages. Especially if it comms from clang. We are so used to the stupid error messages from makeOTF that one tends to ignore them.