alejandro-piguave / TinderCloneSwiftUI

Tinder clone application written using SwiftUI, Firebase, Swift Package Manager and iOS 15 features.
MIT License
89 stars 26 forks source link

Issues in final update #3

Open devhopes-ca opened 1 year ago

devhopes-ca commented 1 year ago

After add Google plist for Firebase, the following errors are coming up all in one file: EditProfileViewModel.swift:

  1. Invalid redeclaration of 'ProfilePicture' on line 11
  2. 'ProfilePicture' is ambiguous for type lookup in this context on line 22
  3. Type of expression is ambiguous without more context on line 30
  4. 'ProfilePicture' is ambiguous for type lookup in this context on line 40
  5. 'ProfilePicture' is ambiguous for type lookup in this context on line 77
  6. Type of expression is ambiguous without more context on line 79
  7. Command SwiftCompile failed with a nonzero exit code

Please assist

Attached is the code:

// // EditProfileViewModel.swift // tinder-clone // // Created by Alejandro Piguave on 27/10/22. //

import Foundation import UIKit

struct ProfilePicture: Hashable{ let filename: String? let picture: UIImage }

class EditProfileViewModel: NSObject, ObservableObject {

private let firestoreRepository: FirestoreRepository = FirestoreRepository.shared
private let storageRepository: StorageRepository = StorageRepository.shared

@Published var userProfile: FirestoreUser? = nil
@Published var userPictures: [ProfilePicture] = []
@Published var isProfileUpdated: Bool = false

@Published private (set) var isLoading: Bool = true
@Published private (set) var error: String = ""

func fetchProfile() {
    self.isLoading = true
    Task{
        do{
            //Fetch profile information
            let user = try await firestoreRepository.getUserProfile()
            DispatchQueue.main.async {
                self.userProfile = user
            }

            //Fetch pictures
            let pictures = try await storageRepository.getPicturesFromUser(fileNames: user.pictures)
            var profilePictures: [ProfilePicture] = []
            for i in user.pictures.indices {
                profilePictures.append(ProfilePicture(filename: user.pictures[i], picture: pictures[i]))
            }

            let finalProfilePictures = profilePictures
            DispatchQueue.main.async {
                self.userPictures = finalProfilePictures
                self.isLoading = false
            }
        }catch{
            publishError(message: error.localizedDescription)
        }
    }
}

//Update only profile fields
func updateProfile(modified profileFields: [String: Any]) {
    self.isLoading = true
    Task{
        do{
            try await firestoreRepository.updateUserProfile(modified: profileFields)

            self.isLoading = false
            self.isProfileUpdated = true
        }catch{
            publishError(message: error.localizedDescription)
        }
    }
}

/**
 Updates the profile pictures

 - Parameter oldPictures: Array of the file names of the pictures that are already uploaded, in their respective order.
 - Parameter newPictures: Array of either: the file name of a picture that is already uploaded or a new picture.
 */
func updateProfile(newPictures: [ProfilePicture], modified profileFields: [String: Any]? = nil){
    self.isLoading = true
    Task{
        let oldPictures = userProfile!.pictures
        //Gets the name of the pictures that are not among the new pictures.
        let filesToDelete = oldPictures.filter({ fileName in
            !newPictures.contains(where: { newPicture in
                if let newPictureFilename = newPicture.filename {
                    return fileName == newPictureFilename
                } else {
                    return false

                }
            })
        })

        let picturesToUpload: [UIImage] = newPictures.compactMap({ pictureUpload in
            if pictureUpload.filename == nil{
                return pictureUpload.picture
            } else {
                return nil
            }
        })

        do{
            async let deletePictures: () = storageRepository.deleteUserPictures(fileNames: filesToDelete)
            async let uploadPictures = storageRepository.uploadUserPictures(picturesToUpload)

            let (_, newFileNames): ((), [String]) = try await (deletePictures, uploadPictures)

            var updatedFileNames: [String] = []
            var count: Int = 0

            newPictures.forEach({
                if let oldFilename = $0.filename {
                    updatedFileNames.append(oldFilename)
                } else {
                    updatedFileNames.append(newFileNames[count])
                    count += 1
                }
            })

            //If more values need to be updated then create a copy, otherwise create an empty dictionary
            var allProfileFields: [String: Any] = profileFields ?? [:]
            allProfileFields["pictures"] = updatedFileNames

            try await firestoreRepository.updateUserProfile(modified: allProfileFields)
            self.isLoading = false
            self.isProfileUpdated = true
        }catch{
            publishError(message: error.localizedDescription)
        }
    }
}

private func publishError(message: String) {
    DispatchQueue.main.async {
        self.error = message
        self.isLoading = false
    }
}

}

devhopes-ca commented 1 year ago

There are more issues coming up, if i can send you the project to see if you can fix it?

havasu78 commented 1 year ago

There are more issues coming up, if i can send you the project to see if you can fix it?

devhopes, i cloned this project from github and four swift files were missing from my download: Persistence.swift, UserProfile.swift, CreateProfileView.swift, and EditProfileView.swift. devhopes, did you create those files yourself?

devhopes-ca commented 1 year ago

No no filea from me.

On Tue, Dec 6, 2022 at 9:23 PM havasu78 @.***> wrote:

There are more issues coming up, if i can send you the project to see if you can fix it?

devhopes, i cloned this project from github and four swift files were missing from my download: Persistence.swift, UserProfile.swift, CreateProfileView.swift, and EditProfileView.swift. devhopes, did you create those files yourself?

— Reply to this email directly, view it on GitHub https://github.com/alejandro-piguave/TinderCloneSwiftUI/issues/3#issuecomment-1340246120, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEEPJ34U5KZ3TZBHWVYRDGTWL7RIVANCNFSM6AAAAAASJ2B52Y . You are receiving this because you authored the thread.Message ID: @.***>

-- Sent from Gmail Mobile

maceip commented 1 year ago

fixed in https://github.com/alejandro-piguave/TinderCloneSwiftUI/pull/4

Lxdro commented 3 months ago

@devhopes-ca, did you figured out how to run the project? I have some packages issues that I struggle to fix. I added my firebase file but build keep failing.