NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

SOLVED: No exact matches in call to instance method 'append'

Forums > SwiftUI

Hello ! So what happens here is that there will be a first loop that just returns the first result and then stops. The idea is rather to collect all the results in an array and then return the result after the loop. But I have an error "No exact matches in call to instance method 'append' " can you help me ?

    func fetchAllFavorites() -> [Favorite] {

        let urls : [URL] = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
        var results: [Favorite] = []
        do {
            for url in urls {
                let favoriteItem = try Data(contentsOf: url)
                let item = try JSONDecoder().decode(Favorite.self, from: favoriteItem)
                results.append(favoriteItem)
                return results
            }
        } catch {
            recordErrorIfNeeded(error)
        }
    }

   

results is an array of Favorite

favoriteItem is of the type Data

You can't add a Data type to an array that holds Favorite types

use append(item) instead

1      

ok it's good ^^thk you

   

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until October 1st.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.