Search results for

swiftui

16,625 results found

Post

Replies

Boosts

Views

Activity

@Published property wrapper not working on subclass of ObservableObject
I have a class conforming to the @ObservableObject protocol and created a subclass from it with it's own variable with the @Published property wrapper to manage state.It seems that the @published property wrapper is ignored when using a subclass. Does anyone know if this is expected behaviour and if there is a workaround?I'm running iOS 13 Beta 8 and xCode Beta 6.Here is an example of what I'm seeing. When updating the TextField on ```MyTestObject``` the Text view is properly updated with the aString value. If I update the ```MyInheritedObject```TextField the anotherString value isn't updated in the Text view.import SwiftUI class MyTestObject: ObservableObject { @Published var aString: String = } class MyInheritedObject: MyTestObject { @Published var anotherString: String = } struct MyView: View { @ObservedObject var myTestObject = MyInheritedObject() @ObservedObject var myInheritedObject = MyInheritedObject() var body: some View { NavigationView { VStack(alignment: .leading) { TextField(Update aSt
0
0
1.6k
Aug ’19
How can you use SwiftUI in a Notification Content Extension?
I can't work out how to use SwiftUI in a notification content extension. It always appears black for me when the extension runs.Here's the code in my extension right now:class NotificationViewController: UIViewController, UNNotificationContentExtension { override func viewDidLoad() { super.viewDidLoad() let child = UIHostingController(rootView: TaskCell_Previews.previews) addChild(child) child.view.frame = view.frame view.addSubview(child.view) child.didMove(toParent: self) NSLayoutConstraint.activate([ child.view.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 1), child.view.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 1), child.view.centerXAnchor.constraint(equalTo: view.centerXAnchor), child.view.centerYAnchor.constraint(equalTo: view.centerYAnchor) ]) } func didReceive(_ notification: UNNotification) { } }In this case, I'm just putting `TaskCell_Previews` in to try to get it working. Whenever I tap on the notification, it just shows a blank view (which has a 1-1 a
0
0
873
Aug ’19
.edgesIgnoringSafeArea not working in tabbed view
Hi,I'm relatively new to coding and am playing around with SwiftUI. Specifically I'm trying to follow Apple's tutorial (https://developer.apple.com/tutorials/swiftui/creating-and-combining-views) to get an understanding. I'm applying the tutorial to a tabbed view app, rather than a single view app. .edgesIgnoringSafeArea(.top) however, does not seem to be working. Is this a specific trait of a tabbed view app?My code looks as following:import SwiftUI struct ContentView: View { @State private var selection = 0 var body: some View { TabView(selection: $selection){ VStack { MapView() .edgesIgnoringSafeArea(.top) .frame(height: 350) CircleView() .offset(y:-130) .padding(.bottom, -130) Text(Hello World) .font(.title) Spacer() } .tabItem { VStack { Image(first) Text(First) } } .tag(0) Text(Second View) .font(.title) .tabItem { VStack { Image(second) Text(Second) } } .tag(1) Text(Third View) .font(.title) .tabItem { VStack { Image(first) Text(Third) } } .tag(2) Text(Fourth View) .font(.tit
1
0
2.3k
Aug ’19
Reply to SwiftUI: How to dismiss the keyboard?
Hi,in order to resize the view to shift up the keybord you can use this code:import Foundation import SwiftUI import Combine import UIKit struct AdaptsToSoftwareKeyboard: ViewModifier { @State var currentHeight: CGFloat = 0 func body(content: Content) -> some View { content .padding(.bottom, currentHeight).animation(.easeOut(duration: 0.25)) .edgesIgnoringSafeArea(currentHeight == 0 ? Edge.Set() : .bottom) .onAppear(perform: subscribeToKeyboardChanges) } //MARK: - Keyboard Height private let keyboardHeightOnOpening = NotificationCenter.default .publisher(for: UIResponder.keyboardWillShowNotification) .map { $0.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect } .map { $0.height } private let keyboardHeightOnHiding = NotificationCenter.default .publisher(for: UIResponder.keyboardWillHideNotification) .map {_ in return CGFloat(0) } //MARK: - Subscriber to Keyboard's changes private func subscribeToKeyboardChanges() { _ = Publishers.Merge(keyboardHeightOnOpening, keyboardHeightOnHiding) .
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’19
How to change TabView background color with SwiftUI?
Default TabView comes in light grey background color. the accentColor modifier works ok for changing the icon selected color, but I can not get the background color to change.Modifiers I've tried: .background(Color.white)This should work, but it doesn't. Could someone point me to the right direction?Thank you!
8
0
29k
Aug ’19
Reply to List updates very slowly and blocks UI
Still broken in Xcode 11b6. Looks like it'll ship this way, unable to make lists of more than a few tens of items!?Kabe, I don't know what enforce a reload means in SwiftUI. Whether the list is passed by value to the component or is a field of an @ObjectBinding doesn't affect the performance. Either way, the resulting view tree gets diffed, including this horrifically slow implementation on the list.
Topic: App & System Services SubTopic: Core OS Tags:
Aug ’19
How Do I Create an NSHostingView?
A bit of background first:I have a document based app that's a file viewer. Each file contains a bunch of tables. Each document window is a horizontal NSStackView. The left hand view shows a list of tables in the file and the right hand view is an NSTabView with two tabs. One to show the unformatted version of the table (i.e. a hex dump) and the other to show a formatted view. Currently the formatted view is a scrollable NSTableView with a single table cell.And my (probably stupid) questions:I want to use a different view for each table type, but I couldn't figure out a way to do that with AppKit. When I learned about SwiftUI, I though it would be easy to create a view that changed based on the table type, and I could put this view into an NSHostingView. I have two questions:1) I thought there'd be a way to create an NSHostingView in the storyboard, just like there is for an NSHostingViewController, but I don't see any way to to that. Have I missed somthing? Is this an as yet unimplemented feature, o
2
0
1.6k
Aug ’19
Xcode Version 11.0 beta 6 (11M392q) - crashing
Since WWDC I've been anxious to take SwiftUI for a test flight. So after clearing out enough room on the SSD in my MBAir and installing Catalina (v10.15 Beta (19A536g)) over a virgin install of Mojave on a new APFS volume and creating a new user account (no migration) I installed Xcode Version 11.0 beta 6 (11M392q) and began the tutorials found here...https://developer.apple.com/tutorials/swiftui/creating-and-combining-viewsI completed the first Creating and Combining Views with not so much as a bump and could not help but be impressed by the streamlined SwiftUI workflow. Bouyed with optimism I launched into the second tutorial, found here...https://developer.apple.com/tutorials/swiftui/building-lists-and-navigationand that is where the balloon burst. I have spent hours trying to determine what it is in Apple's code that is making xcode bark with a seemingly randow error message almost every time I run the preview, which would be maddening enough but every once in a dogs ag
2
0
1.1k
Aug ’19
How to change List's cell background color alternately in SwiftUI?
Hi,I want to create diffrent cell with seperate color in a section. Reagards,Ranjeetstruct AlternateListCellView: View { var body: some View { List { Section(header: Text(Show alternate cell)) { ForEach(1...5) { row in Text(Row Index = (row)) } // row variable is out of scope, so its throw compile time error. Is any other way to create section and cell? // Kindly correct me if Any mistake. // .listRowBackground(row % 2 == 0 ? Color.orange : Color.yellow) } } .background(Color.purple) } }
1
0
1.8k
Aug ’19