VesselWheel

[SwiftUI] Allow Arbitrary Loads, 외부 URL 허용 본문

Xcode Study

[SwiftUI] Allow Arbitrary Loads, 외부 URL 허용

JasonYang 2023. 4. 29. 15:16

App Transport Security Settings에서 Allow Arbitrary Loads  허용한 인포 모습

-> ATSetting에서 오른쪽 마우스 "add Row" 클릭하여 하위 설정으로 'Allow Arbitrary Loads, boolean, yes로 설정

 

struct Menu : Identifiable{

    var id = UUID()

    var name : String

    var price : String

    var imageURL : String

    var message : String

}

 

struct MenuRow : View{

    var menu : Menu

    @Binding var showToast : Bool

    @Binding var toastMessage : String

    var body: some View{

        HStack{

            WebImage(url: URL(string: menu.imageURL))

                .renderingMode(.original)

                .resizable()

                .placeholder{

                    Rectangle().foregroundColor(.gray)

                }

                .indicator(.activity)

                .transition(.fade(duration: 0.5))

                .scaledToFit()

                .frame(width: 100, height: 100, alignment: .center)

            Text("\(menu.name)")

                .font(.title)

                .multilineTextAlignment(.leading)

                .frame(width: 150.0)

            Text("\(menu.price)")

                .font(.footnote)

        }

        .onTapGesture {

            print(menu.message)

            self.toastMessage = menu.message

            self.showToast.toggle()

        }

    }

}

 

struct Coffee_Menu1View: View {

    @State private var showToast = false

    @State private var toastMessage = "..."

    var body: some View {

        var menuList : Array<Menu> = Array()

        var index = 0

        for _ in names{

            let menu: Menu = Menu(name: names[index], price: prices[index], imageURL: images[index], message: messages[index])

            menuList.append(menu)

            index += 1

        }

        return List(menuList) { menu in

            MenuRow(menu: menu, showToast: self.$showToast, toastMessage: self.$toastMessage)

        }

        .navigationTitle("coffee")

        .navigationBarTitleDisplayMode(.inline)

        .toast(isPresenting: self.$showToast){

            AlertToast(displayMode: .banner(.pop), type: .regular, title: self.toastMessage)

        }

    }

}

 

struct Coffee_Menu_View_Previews: PreviewProvider {

    static var previews: some View {

        Coffee_Menu1View()

    }

}

 

ex12.zip
0.53MB

-> 백다방 예제로 본 프로젝트파일 첨부

'Xcode Study' 카테고리의 다른 글

변수 간 연결(Value binding pattern)  (0) 2023.05.02
Guard 문의 개념  (0) 2023.04.30
[SwiftUI] webview 사용 코드  (0) 2023.04.29
[SwiftUI] cocoapods 설치 및 사용  (0) 2023.04.29
[SwiftUI]switch 문의 개념  (0) 2023.04.26