Hey guys,
I'm totally new to Swift programming and I'm setting up a view for registering users. I use a VStack to organize the TextFields as well as a DatePicker, but the last one seems to be very rebellious.
Here's my code:
VStack {
TextField("E-Mailadresse", text: $mail)
.frame(height: 30)
.textFieldStyle(.roundedBorder)
.multilineTextAlignment(.center)
.focused($hasFocus, equals: .mail)
.onKeyPress(.tab, action: {hasFocus = .password; return .handled})
SecureField("Passwort", text: $password)
.frame(height: 30)
.textFieldStyle(.roundedBorder)
.multilineTextAlignment(.center)
.focused($hasFocus, equals: .password)
.onKeyPress(.tab, action: {hasFocus = .name; return .handled})
TextField("Name", text: $name)
.frame(height: 30)
.textFieldStyle(.roundedBorder)
.multilineTextAlignment(.center)
.focused($hasFocus, equals: .name)
.onKeyPress(.tab, action: {hasFocus = .prename; return .handled})
TextField("Vorname", text: $prename)
.frame(height: 30)
.textFieldStyle(.roundedBorder)
.multilineTextAlignment(.center)
.focused($hasFocus, equals: .prename)
.onKeyPress(.tab, action: {hasFocus = .birthday; return .handled})
DatePicker("Geb.:", selection: $birthday, displayedComponents: [.date])
.datePickerStyle(.wheel)
.clipped()
//.focused($hasFocus, equals: .birthday)
Button("Registrieren") {self.register()}
.padding(.top, 20)
.keyboardShortcut(.defaultAction)
}
.frame(width: 375)
}
And this is how it looks like:
As you can see, neither is the DatePicker centered correctly (it's more left located) nor is it clipped (reduced). I also tried adding a .frame() to itself, then I was ably to reduce it to the preferred height, but I can' reduce its width and as a result of this, I can also not write a full label like "Date of Birth" or something, because the wheel of the DatePicker always overlays it...
Is that a kind of misbehavior or am I missing something?
Thank you very much in anticipation for your feedback!
Kind regards
Kevin
Post
Replies
Boosts
Views
Activity
Hey guys,
I'm totally unexperienced in Swift coding and I'm doing my first steps using Swift Playgrounds on my macOS as well as on my iPadOS.
I'm setting up a simple App that can be divided in 4 main categories (Splash, Authentication, Content, Setup). Each category (except the Splash as the short intro when running the app) can have a NavigationStack (e. g. switching between login view, register view, forgott password view in authentication). So I thought about having a root view for each of them. My google research gave me lots of ways and hints but it's not clear at all for me if I should and how I should do this. I often read about a RootViewController but I guess that's UIKit stuff and nothing for SwiftUI. Then I read about delegates and such. Then, I read an article that exactly fits my goals and I just liked to get your opinion what you think about this way to solve my plan:
First of all, I define a separate class for a appRootManager:
final class appRootManager: ObservableObject {
enum eRootViews {
case Splash, Authentification, Content, Setup
}
@Published var currentRoot: eRootViews = .Splash
}
The main app file looks like this:
@main
struct MyApp: App {
@StateObject private var oRootManager = appRootManager()
var body: some Scene {
WindowGroup() {
Group {
switch oRootManager.currentRoot {
case .Splash:
viewSplash()
case .Authentification:
viewLogin()
case .Content:
viewContent()
case .Setup:
viewSetup()
}
}
.environmentObject(oRootManager)
.modelContainer(for: [Account.self])
}
}
}
In each of the for root view files (e. g. Splash view) I make the appRootManager addressable and switch the root view by updating the enum value, like for example:
struct viewSplash: View {
@EnvironmentObject private var oRootManager: appRootManager
var body: some View {
ZStack {
Color.blue
.ignoresSafeArea()
Text("Hello World")
.font(.title)
.fontWeight(.semibold)
.foregroundColor(.white)
}
.onAppear() {
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
withAnimation(.spring()) {oRootManager.currentRoot = .Authentification}
}
}
}
}
It works fine and does exactly what I like to have (when I run the app out of Swift Playgrounds). I'm just wondering why it does not work in the App Preview in Swift Playgrounds and this is why I'd like to have your opinion to the way I solve my plan.
I'm very happy for any feedback. Thanks a lot in anticipation!
Kind regards
Kevin
Hey,
I'm very new to the world of Apple now and I'd like to start programming on iOS and MacOS. Till now, I'm very familiar to C++ by using the Qt IDE.
Well, as I'm starting from zero now, I have a fundamental question and depending on that, maybe one other question:
By doing a google research, I read a lot about disadvantages using C++ with XCode. But in other threads and posts, even the more recent posts, I read that XCode can handle C++ very well.
So, what is your opinion? Is it possible to achieve 100 % of the functionallity on iOS and macOS by programming with C++ on XCode (or even an other IDE like VS Code or Qt) or is there always less functionallity then using Swift?
If there was no difference between C++ and Swift at all (functionallity, performance, memory and so on...), then my second question is:
Do I have to use XCode for C++ or would it even be better to use VSC oder another editor/IDE?
Again, I'm very new to Apple, I bought an MacBook and an iPhone and I read a lot about XCode beeing the one and only IDE for programming on macOS / iOS, and, for that, Swift was the best language to use it.
So what is your opinion? Is everything achievable on iOS/macOS using C++ instead of Swift? If yes: Is there full functionallity programming C++ in XCode instead of using Swift in XCode or should I better use an other editor/IDE on my device?
Thank you very much in anticipation!
Kind regards,
KeRaBe