Posts

Post marked as solved
8 Replies
7.0k Views
Hello! I am struggling with the most basic things :-( I created a Swift Package with the wizard and left it basically untouched, only added a func: public struct TestPackage {     public init() {     }     public static func hello()     {         print("Hello, World!")     } } It just build fine. Now I created a second project, this time a SpriteKit iOS app. In the file list on the left, right-clicked on "Packages" -> "Add Packages ..." -> "Add Local" and selected the root directory of TestPackage (containing the Package.swift) The Package now correctly appears in the "Packages" folder. Opening a random Swift file in said SpriteKit iOS app, I expect to be able to import TestPackage But it tells me "No such module TestPackage". Searching the internet, I somewhere read that I have to add the package also to the "Frameworks, Libraries and Embedded Content" section in the project's target settings, but I can't. Hitting the "+" button there does not give me my library in the list of suggested libraries. Via "Add Other" -> "Add package dependency" -> "Add Local ..." I can again select the root directory of my library, but other than showing up twice in the left-side folder view (and not in said Frameworks, Libraries and Embedded content", I have no luck in importing it to my code. What am I doing wrong?
Posted
by s_zapo.
Last updated
.
Post not yet marked as solved
0 Replies
409 Views
Hello! I am thinking about creating a macOS app that requires one or multiple touch interfaces. Apart from using Wifi - is there something high- or low-level available to enable communication (RPC or TCP/UDP) directly via the wired connection? I found https://github.com/jensmeder/DarkLightning - would this be the right thing?
Posted
by s_zapo.
Last updated
.
Post marked as solved
1 Replies
779 Views
I am developing an app that contains a SpriteKit scene embedded inside a SwiftUI context.I am trying to render a simple SKShapeNode like this:import Foundation import SpriteKit class UIConnection: SKShapeNode { override init() { super.init() self.fillColor = UIColor.clear self.strokeColor = UIColor.blue self.lineWidth = 0.01 } func updatePositions(node1 : CGPoint, node2 : CGPoint) { let path = CGMutablePath() path.move(to: node1) path.addLine(to: CGPoint(x: node1.x, y: node2.y)) path.addLine(to: CGPoint(x: node2.x, y: node2.y)) path.addLine(to: CGPoint(x: node2.x, y: node1.y)) path.addLine(to: node1) self.path = path } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } }When I am adding that Node inside the standard SpriteKit game project template in XCode (without any SwiftUI things), everything is working fine, I get a non-filled rectangle with a blue outline. The frame.width and frame.height variables are valid pixel dimensions like 750 x 1334.let node = UIConnection() self.addChild(node) node.updatePositions(node1: CGPoint(x: frame.midX-frame.width/4, y: frame.midY-frame.height/4), node2: CGPoint(x: frame.midX+frame.width/4, y: frame.midY+frame.height/4))Now I want to embed the SKScene inside a SwiftUI context using this approach:https://dev.to/sgchipman/using-spritekit-with-swiftui-ibcFirst thing I encounter is the fact that frame.width and frame.height both result in a value of 1.Adding the above node to the embedded SKScene results in an extremely blurred rectangle, so no solid line but some weird cloudy object.
Posted
by s_zapo.
Last updated
.
Post not yet marked as solved
4 Replies
592 Views
Hi!I am a long-time Java developer and new to Swift, currently writing my first iOS app.I am writing an app similar to VVVV or Quartz composer, where you have a set of nodes processing some data and passing the output to a series of listening nodes.I know the concept of abstract functions is not present in Swift, so I tried to use protocols.So there's a super-class Node, which holds a Set of other Nodes implementing a protocol.import Foundation class Node : Equatable, Hashable { var id: Int var name : String? var listeners : Set<MessageListener>! init() { self.name = „Bla“ self.id = 0 self.listeners = Set<MessageListener>() } func hash(into hasher: inout Hasher) { hasher.combine(id) hasher.combine(name) } static func == (lhs: Node, rhs: Node) -> Bool { return (lhs.id == rhs.id) && (lhs.name == rhs.name) } func addListenerNode(node : Node) { listeners.insert(node) } func removeListenerNode(node : Node) { listeners.remove(node) } internal func output(message: CircuitMessage) { for node in listeners { node.receive(message: message) } } }The protocol consists of just one function receive(message: NodeMessage).protocol MessageListener : Hashable { func receive(message: NodeMessage) }I have various subclasses of Node, e.g. SpecialNode1, SpecialNode2, etc. which all do some fancy things upon receiving and use the super class's method to distribute in to the connected nodesimport Foundation class SpecialNode1 : Node, MessageListener { init() { super.init() } func receive(message: NodeMessage) { //do some fancy stuff to the NodeMessage //and send it out to the listeners output(message: midiMessage) } }This approach does not work, because apparently the protocol needs to be Hashable in order to be collected in a Set.I tried an alternative approach and left out the Protocol, having a Set of <Node> in the Node class and putting the receive() function there, with the subclasses overriding that function. That however leads to the problem that the receive function is always called in the superclass, and not in the respective subclass.Any ideas how to achieve this?
Posted
by s_zapo.
Last updated
.