You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
structContentView:View{@Statevarcounter=0varbody:someView{VStack{Text("Hello no \(counter) from SwiftUI").padding()UILabel()// <- This can be any `UIKit` view..swiftUIView(layout:.intrinsic)// <- This is returning a SwiftUI `View`..set(\.text, to:"Hello no \(self.counter) from UIKit")// <- Use key paths for updates..fixedSize()}.onAppear{
if counter ==0{schedule()}}}func schedule(){
counter +=1DispatchQueue.main.asyncAfter(deadline:.now()+ 0.5){self.schedule()}}}
I expected the UILabel to be updated and behave like my SwiftUI Text-view, but instead it is showing just 0. Also, recreating the UILabel every time the view hierarchy is declared is not a good idea as it may happen many many times. I think this is a fundamental issue with the approach in this library. I find this approach better and easier
import SwiftUI
import UIKit
structUIViewMaker<ViewType:UIView>:UIViewRepresentable{typealiasUIViewType=ViewTypevarmake:()->ViewType=ViewType.init
varupdate:(ViewType)->()func makeUIView(context:Context)->ViewType{returnmake()}func updateUIView(_ uiView:ViewType, context:Context){update(uiView)}}structContentView:View{@Statevarcounter=0varbody:someView{VStack{Text("Hello no \(counter) from SwiftUI").padding()
UIViewMaker<UILabel>{
$0.text ="Hello no \(self.counter) from UIKit"}.fixedSize()}.onAppear{
if counter ==0{schedule()}}}func schedule(){
counter +=1DispatchQueue.main.asyncAfter(deadline:.now()+ 0.5){self.schedule()}}}
The text was updated successfully, but these errors were encountered:
I expected the UILabel to be updated and behave like my SwiftUI Text-view, but instead it is showing just 0. Also, recreating the UILabel every time the view hierarchy is declared is not a good idea as it may happen many many times. I think this is a fundamental issue with the approach in this library. I find this approach better and easier
The text was updated successfully, but these errors were encountered: