Search results for

swiftui

16,584 results found

Post

Replies

Boosts

Views

Activity

Reply to Is it possible to read individual keystrokes in a TextField?
hi,EDIT: OOPS - missed that this is a SwiftUI question (and i'm not there yet), so not sure if the following really answers the question ⚠you might want to go back to the topic Understanding UITextView Input of May 10 and using the shouldChangeText(in:replacementText:) method (part of UITextInput protocol that UITextField conforms to).in short, shouldChangeText(in:replacementText:) gives you a more general way to see what's coming into a UITextField before it gets there (which could be from a keystroke, but also from a paste); it may do what you need, but i don't know that there's a direct keystroke reader (assume you're talking about iOS).hope that helps,DMG
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’19
You can stroke or you can fill a shape, but you can't do both?
I was playing with drawing shapes and got stuck trying to fill and stroke them with different colors.Both lines 6 and 7 work fine in isolation but, together, they give a compiler error. I understand *why* there's an error - it's because applying either of those lines in isolation changes the type from `Circle` to some other type (`ShapeView<StrokedShape<Circle>, Color>` or `ShapeView<Circle, Color>`) and that other type doesn't support stroking or filling - but I don't think the API should be so counter-intuitive.More importantly, what *is* the correct way to apply both a stroke color and a fill color to a shape?import SwiftUI struct CircleView : View { var body: some View { Circle() .stroke(Color.green, lineWidth: 5) //.fill(Color.orange) } } #if DEBUG struct CircleView_Previews : PreviewProvider { static var previews: some View { VStack { CircleView() .background(Color.primary) .colorScheme(.light) CircleView() .background(Color.primary) .colorScheme(.dark) } } } #endif
0
0
558
Jun ’19
How to preview a custom View that takes bindings as inputs in its initializer?
Say you have the following view:import SwiftUI struct BindingViewExample_1 : View { @State var value = false private var text: String { Toggle is + (value ? 'on' : 'off') } var body: some View { HStack { Toggle(isOn: $value) { Text(text) } } .padding([.leading, .trailing], 80) } } #if DEBUG struct BindingViewExample_1_Previews : PreviewProvider { static var previews: some View { BindingViewExample_1(value: true) } } #endifThis previews fine and you can interact with the control in the preview and see the changes immediately.But what if it took a *binding* as input? Consider this alternate version of the same view:import SwiftUI struct BindingViewExample_2 : View { @Binding var value: Bool private var text: String { Toggle is + (value ? 'on' : 'off') } var body: some View { HStack { Toggle(isOn: $value) { Text(text) } } .padding([.leading, .trailing], 80) } } #if DEBUG struct BindingViewExample_2_Previews : PreviewProvider { @State static var value = false static var previews: some View { B
7
0
34k
Jun ’19
Reply to Using print()
In SwiftUI, views are created inside the definition of a structure and then initialized when an instance is created from that definition, therefore, you can't execute code anywhere you want, you can only do it from inside the structure's methods or closures. For instance, if you look at your code, you tried to call the print() function in the place were the properties of the structure and its methods are defined. This is not allowed. If you want to execute code when the instance of that structure is created, you have to define the structure's initializer:import SwiftUI struct TestView : View { let myvar = 150 init() { print(myVar: (myvar)) } var body: some View { Text(Hello World!) } }The body property is a computed property which value is defined by a closure, so you can use print() inside that closure. The problem is that closures know what value to return when they only have one statement, but if there are more than one statement, you have to specify what should be returned with the retur
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’19
Reply to How to make a resizable HSplitView for macOS?
Without navigation, the closest one can do is generate new views for every clickimport SwiftUI struct ContentView : View { @State var clickedContent: RandomListStruct? @State var clickedUseCase: Int? var var_list : [RandomListStruct] let zero = use a default view as in WWDC video var body: some View { HStack (alignment: .top) { VStack (alignment: .leading){ List (selection: $clickedContent) { Text (Master Record).color(.orange) Divider() ForEach(var_list.identified(by: .self)) { rls in HStack { Text((rls.name)) Spacer() Text((rls.address)) } } } }.frame(maxWidth: 250, maxHeight: .infinity) VStack { List { Text (Details ).color(.orange) Divider() if (clickedContent?.name ?? zero) == zero { Text(Please select a Row).color(.red) } else { VStack(alignment: .leading) { Text(Name : (clickedContent!.name)).color(.green) Text(Address : (clickedContent!.address)).color(.green) } } } }.frame(maxWidth: 500, maxHeight: .infinity) } } } struct RandomListStruct: Hashable, Codable, Identifiable { var id : Int var n
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’19
Reply to Xcode 11 Beta 2 stuck on showing file dialog.
I have the same problem!In Xcode 11 Beta 1 sometimes I can open my app but not everytime !I might mistake choosing SwiftUI when launching my app which using UIKit.In the release note it said:Xcode 11 beta doesn’t support working with SwiftUI in a project configured to use UIKit for Mac. (51201699)Since then no luck !
Topic: App & System Services SubTopic: Core OS Tags:
Jun ’19
SwiftUI List with Toggle binding with model
I've got a model with a bool variable that i'll need to bind with a SwiftUI Toggle that is displayed in a List.import SwiftUI struct MyModel : Identifiable { var id: String var name: String var notify: Bool }import SwiftUI struct ContentView : View { var myModels: [MyModel] = [] var body: some View { NavigationView { List(myModels) { myModel in Toggle(isOn: myModel.notify) { Text(myModel.name) } } .navigationBarTitle(Text(My Models)) } } } #if DEBUG struct ContentView_Previews : PreviewProvider { static var previews: some View { ContentView(tickets: MyModel.mockModels) } } #endifWhen the user interacts with the toggle, i'll need the variable `notify` in the model to update.The only example that i've looked at that implements a Toggle is the WorkingWithUIControls - LandmarkList but i can't seem to get it to work with an array of MyModels.Any help would be much appreciated.
3
0
12k
Jun ’19
SwiftUI: SF Symbols NOT displayed on device
I'm following tutorials https://developer.apple.com/tutorials/swiftui/handling-user-input. After adding the yellow star using SF Symbols, I found that the symbols is missing using live mode either on device(iPhone X and iPad Pro 10.5) or on the simulators. I tested on the completed sample file and the issue reappears. I'm using the macOS beta 2, xcode beta 2 and ios beta 2.The code to draw the star:Image(systemName: star.fill) .imageScale(.medium) .foregroundColor(.yellow)This issue reappears whether using modifiers or not.
1
0
5.0k
Jun ’19
SwiftUI and mapkit
Hi all....i am moving a current app to SwiftUI. The app has mapkit map object view with a an annotation in. It is just a standard annotation nothing fancy, but with custom name. Example...pin on my house...name Mike's house Moving to SwiftUI; if I include mapkit in its own Some view it's fine the pin works perfectly. Now if I have a summary view that uses a Navbar to move to a detail view and on that detail view is this new map view the name of the pin is shown but not the pin itself.Example list view-Mike's House -> via navbar to detail view -Phil's House-Craig's House Mikes HouseAge 19522 floorsMap ( with pin annotation)the code should work, but I am going insane trying to work out why as soon as it is in a sub view the pin is not being shown. The map is correctly at the correct location, and the annotation is being shown....it's just the graphic for the pin. setup is Catilina beta 1, Xcode beta 2. code is very similar to apple tutorial except it adds annotations- going nuts
2
0
1.2k
Jun ’19
Reply to SwiftUI and mapkit
What makes this strange if the map is its own view the pin is correctly shown. As soon as it comes from a navigation view then the pin is not shown...wondering if it is a bug or a 'feature'what would help would be a proper swiftui implementation of mapkit lol, but can someone help in the meantime
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’19
Xcode Preview error: "A coordinated install for ... is already pending."
Hi,When testing my SwiftUI code, I sometimes get the new Xcode preview system having this error:Error Domain=IXErrorDomain Code=29 A coordinated install for xxxx is already pending. UserInfo={NSLocalizedDescription=A coordinated install for xxxx is already pending., SourceFileLine=143, FunctionName=+[IXAppInstallCoordinator(IXSimpleInstaller) _beginInstallForURL:consumeSource:options:completion:]_block_invoke, NSLocalizedFailureReason=Unhandled reason for code: 29 in domain IXErrorDomain}The workaround I have found is to reboot my Mac (I will edit this post if I find a less radical workaround).Note: Version 11.0 beta 2 (11M337n)
3
0
6.3k
Jun ’19
Reply to Core Data Model SwiftUI
There are some examples of using Core Data with SwiftUI showing up on github and the web:https://github.com/StephenMcMillan/Dub-Dub-Dohttps://github.com/italoboss/EmotionalDiaryhttps://medium.com/@rosscoops/swiftui-nsfetchedresultscontroller-f9f27718e3d4They seem to work with simple models (one entity), haven't seen any code based on more complex models (multi-entity with relationships) yet, nor have I been able to get a more complex model to work.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’19