Wednesday, February 21, 2024
HomeiOS Developmentios - Results of 'AnimalListItemView' initializer is unused

ios – Results of ‘AnimalListItemView’ initializer is unused


It has been fairly a while that I’ve coded in SwiftUI. I’m kinda new in creating functions for current model of iOS…

The warning lies within the #Preview of my AnimalListItemView.

import SwiftUI

struct AnimalListItemView: View {
    
    //let animals: [Animal] = Bundle.essential.decode("animals.json")
    //let animal: [Animal] = Bundle.essential.decode("animals.json")
    //let animal: Animal = Bundle.essential.decode("animals.json")
    
      let animal: Animal
//
//    init(animal: Animal) {
//        self.animal = animal
//    }
    
    var physique: some View {
        
        //ForEach(0..<5) { _ in
            HStack(alignment: .middle, spacing: 16) {
                Picture(animal.picture)
                    .resizable()
                    .scaledToFill()
                    .body(width: 90, peak: 90)
                    .clipShape(RoundedRectangle(cornerRadius: 12))
                
                VStack(alignment: .main, spacing: 8) {
                    Textual content("Lion")
                        .font(.title2)
                        .fontWeight(.heavy)
                        .foregroundStyle(.accent) //units the accent coloration of the textual content
                    
                    Textual content("The worlds most social felines, lions room the savannas and grassland of the african continent , searching cooperatively and elevating cubs in pleasure.")
                        .font(.footnote)
                        .multilineTextAlignment(/*@START_MENU_TOKEN@*/.main/*@END_MENU_TOKEN@*/)
                        .lineLimit(2)
                        .padding(.trailing, 8)
                } //: VSTACK
            } //: HSTACK
        //} //: FOR LOOP
    }
}

#Preview {
    let animals: [Animal] = Bundle.essential.decode("animal.json")
    //AnimalListItemView(animal: animals[1])
    AnimalListItemView(animal: animals[1])
}

//struct AnimalListItemView_Previws: PreviewProvider {
//    static let animals: [Animal] = Bundle.essential.decode("animals.json")
//    
//    static var previews: some View {
//        AnimalListItemView(animal: animals[1])
//    }
//}`

It says:

Results of ‘AnimalListItemView’ initializer is unused

Right here is my AnimalModel.swift:

import SwiftUI

struct Animal: Codable, Identifiable {
    let id: String
    let title: String
    let headline: String
    let description: String
    let hyperlink: String
    let picture: String
    let gallery: [String]
    let truth: [String]
}

Anybody with some resolution. I do know its a foolish query, however HELP!

Anticipating for an answer…



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments