Post

Replies

Boosts

Views

Activity

Comment on Inconsistent behavior in invoking a Swift method from a different class?
Vectors is the name of the project. Using breakpoints, I have verified that Renderer is invoked once to set up the MTKView. The draw method is called repeatedly and doesn't instantiate Renderer. Since dodraw() behaves differently depending upon where it is called from, I wonder whether calling it using the graphRef instance as a reference to it might be the problem - could the instance not respect the @IBOutlet created in GameViewController? That would be odd, but maybe I needed an init?
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’23
Comment on Inconsistent behavior in invoking a Swift method from a different class?
If I put the print statement just before the needsDisplay=true statement in dodraw() I get: "dodraw() graph = nil". As expected. Still, the outlet seems OK. On the other hand, if I place the print statement in the slider function (and remove dodraw from the renderer loop) I get "dodraw() graph = Optional(<Vectors.GraphView: 0x1221256c0>)" and the graph is updated normally. Same function, different result for graph when dodraw is called from the two different places. Interesting!
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’23
Comment on draw in swift does not respond to needsDisplay = true
I removed the dodraw() reference from the draw method and placed it in one of the methods in GameViewController. Not surprisingly, it worked fine there: I put the method in a mouse routine and moving the mouse caused the drawing to take place. I guess that Swift is implacable about keeping methods in view controllers from being accessed from a different class. I will look into delegation.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’23
Comment on draw in swift does not respond to needsDisplay = true
I removed the dodraw() reference from the draw method and placed it in one of the methods in GameViewController. Not surprisingly, it worked fine there: I put the method in a mouse routine and moving the mouse caused the drawing to take place. I guess that Swift is implacable about keeping methods in view controllers from being accessed from a different class. I will look into delegation.
Topic: Programming Languages SubTopic: Swift Tags:
Aug ’23