To start off with the Backend, we set up a Kotlin/Native Project in IntelliJ. Setting up a Kotlin/Native Project in IntelliJ We’ll get back to the Xcode project later, when we want to use Kotlin code, but for now, let’s set up the Backend. With these steps done, we have a project that when runs presents a little window with “Hello World!” in it (at the time of making).
Important points are that we want to use Swift with SwiftUI and no Core Data, since persistent data storage will be handled by the Kotlin/Native Backend. First off, we set up a fresh Xcode project for MacOS:
#Swift mac os framework code
We also want to be able to use that code from our Frontend which in this case is a Mac native application using SwiftUI – and AppKit where SwiftUI is not sufficient. Ok, we want to set up a Time Tracking app with a shared Kotlin/Native Backend. Setting up SwiftUI and Kotlin/Native projects Making the Kotlin framework available in Xcode.
Changing the Kotlin project from executable to framework.As a god darn Frog! Oh, well, better get to it and get this sh*t done.Īrthur will do the Windows part, so I guess I’m stuck with Swift. I hate Tuesdays! And now I have to develop some stupid time tracking app for her, awesome. This means you can now learn one language and one layout framework, then deploy your code anywhere.Dammit, that’s typical… Turned into a frog by some Organizational Change Specialist M anager witch. That’s what it means by declarative: we aren’t making SwiftUI components show and hide by hand, we’re just telling it all the rules we want it to follow and leaving SwiftUI to make sure those rules are enforced.īut SwiftUI doesn’t stop there – it also acts as a cross-platform user interface layer that works across iOS, macOS, tvOS, and even watchOS.
#Swift mac os framework update
We already told it what to show based on whether the user was logged in or out, so when we change the authentication state SwiftUI can update the UI on our behalf. Instead, we let SwiftUI move between user interface layouts for us when the state changes. We don’t need to write code to move between those two states by hand – that’s the ugly, imperative way of working! We might say if we’re logged in show a welcome message but if we’re logged out show a login button. In contrast, declarative UI lets us tell iOS about all possible states of our app at once. If you’ve ever used an app that says you have 1 unread message no matter how many times you try to tell if you’ve read the darn thing, that’s a state problem – that’s an imperative UI problem. If we have two Booleans, A and B, we now have four states:Īnd if we have three Booleans? Or five? Or integers, strings, dates, and more? Well, then we have lots more complexity. If we have one screen with one Boolean property that affects the UI, we have two states: the Boolean might be on or off. Imperative UI causes all sorts of problems, most of which revolve around state, which is another fancy term meaning “values we store in our code.” We need to track what state our code is in, and make sure our user interface correctly reflects that state. In an imperative user interface we might make a function be called when a button was clicked, and inside the function we’d read a value and show a label – we regularly modify the way the user interface looks and works based on what’s happening.
#Swift mac os framework how to
That’s a fancy way of saying that we tell SwiftUI how we want our user interface to look and work, and it figures out how to make that happen as the user interacts with it.ĭeclarative UI is best understood in comparison to imperative UI, which is what iOS developers were doing before iOS 13. SwiftUI is a user interface toolkit that lets us design apps in a declarative way.