|
Hey there, one and all! Pretty new to the world of Swift and development on iOS, still waiting to become an Apple developer. But in the meantime I figured I would "get my hands dirty" and fiddle about with Xcode and SwiftUI for a bit. Do note that I am "stuck" on Xcode 12.4 (Swift 5.3 if I'm not mistaken) and macOS 10.15 (still have an old MacBook Pro, looking to upgrade sometime next year). Not new to programming, having started with Basic on MSX, C on Amiga, Asm on PC and professionally as front- and backend developer for web; Javascript, PHP. Also experience with Python, Ruby and Rust. The code in question (posted below) will be sending a "heartbeat" to an external server (in the final code) every 2 seconds, and will be receiving data on port 9876 at a rate of up to 60 Hz. As it stands, not being a registered Apple developer I am stuck on just listening to the UDP port and can't send the "heartbeat", but I don't foresee any real issue with that part. I have verified that this works at least in the Xcode simulators, but I figured maybe someone could take a look and see if anything sticks out as a "heck no, don't do that!" 😂
|
|
One line 3 instead of
Sample
Disclaimer - i am also a noob 😁 |
|
Ahh, I see, I have to read up on that, but I get the distinction. As it stands I instantiate it in the @main in the TestApp.swift, like this:
But I surmise that having the ContentView own it is better. I'm mostly amazed I managed to get it going as far as this in a week. That includes compiling a Rust salsa20 decoding (a special doohickey) framework to handle the data received by the UDP connection. I was unable to get a pre-existing salsa20 implementation to work properly with my limited understanding of the intricacies of Swift (possibly related to me being on an older version of Xcode and Swift), so I am happy with the progress at least :D |
|
Something that you may or may not already know. The
In Swift, if you have a closure that is supposed to return a value, and you only have one line of code in that closure, it will automatically assume that the value expressed in that one line of code is the value that should be returned. What you have written isn't really wrong. But, just thought I'd point it out in case you didn't know. So you could write it like this...
|
|
Indeed @Fly0strich, now that you mention it, I kind of knew that already. But thanks for pointing it out, and as you say; not wrong, but I may as well do it the conventional way from the get-go. Harder to get rid of bad coding habits later on. Having too many various programming languages stored away, it gets you sometimes :D My mind is too single-threaded in these multi-threaded times! |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.