Post

Replies

Boosts

Views

Activity

protocol in swiftUI
I've been reading the documentation and apparently protocols force structures, classes or enumerations to implement specific methods or define certain variables. I've double checked this functionality by typing the following code. In fact, xcode compiler helped me to verify this since it popped up an alert that depicted the following message : "Type MiguelStruc does not conform to protocol Miguels ..." protocol Miguels { func someF()-> Float } public struct MiguelStruc{ var miguelVar : String = "hey" } extension MiguelStruc: Miguels{ } Now, while I was following the official swiftUI drawing paths and shapes tutorial I encountered this particular chain of code: (https://developer.apple.com/tutorials/swiftui/drawing-paths-and-shapes) Path { path in } .fill(.black) By diving into the Swiftui documentation I noticed that Shape is a protocol public protocol Shape : Sendable, Animatable, View which is implemented by the Path structure extension Path : Shape Why none of the Path extensions content are explicitly implementing any of the Shape protocol requirements? such as role, layoutDirectionBehavior, sizeThatFits, offset, intersection, union, and so on!
4
0
480
May ’24
swiftui bottom padding has no effect on a geometryreader view component
I was following the Swiftui tutorial at section 6 (https://developer.apple.com/tutorials/swiftui/creating-and-combining-views) to use a circle image to create an overlapping effect on the map. Turns out that when using a GeometryReader, the bottom padding was not working at all: VStack{ MapView().frame(height:300) CircleImage() .offset(y: -130) .padding(.bottom, -130) VStack(alignment:.leading){ Text( "Turtle Rock" ) .font( .title ) HStack { Text( "Joshua Tree National Park" ) .font( .subheadline ) Spacer() Text( "California" ) .font( .subheadline ) } }.padding(/*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/) } This is the code for the CicleImage view: GeometryReader(content: { geometry in let _ = print( geometry.size.width ) AsyncImage( url: URL( string: "https://cms.rationalcdn.com/v3/assets/blteecf9626d9a38b03/bltf5486c52361f2012/6144fafd39dff133fc23de9f/img-ios.png" ) ) .frame(width: geometry.size.width) .clipShape( Circle() ).overlay{ Circle().stroke( .white, lineWidth: 4 ) }.shadow( radius: 7 ) })
0
0
384
May ’24
VStack initialization without parentheses
Hi everyone I'm new to swiftui and I'm trying to understand the reason that allows swiftui to call a VStack or any other container view without parentheses as in: struct ContentView: View { var body: some View { VStack { Text("sth"); } } } After looking into the swift docs, it was clear as in any other programming language that instantiating a class/structure is made by calling the entity with its parentheses, an even passing some parameters if possible. Isn't should be the case for placing view components in the body computer property? So far my mind keeps telling me that the syntax should follow this convention struct ContentView: View { var body: some View { VStack() { Text("sth"); } } } At which concept should I look into for further clarifications All the best.
2
0
341
May ’24