Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bookmark di ArticleListView #4

Closed
dekapd99 opened this issue Jun 7, 2022 · 1 comment
Closed

Bookmark di ArticleListView #4

dekapd99 opened this issue Jun 7, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@dekapd99
Copy link
Owner

dekapd99 commented Jun 7, 2022

Aplikasi tetap berjalan cuma gak menampilkan berita apapun karena ada masalah di image icon bookmark

Penyebab error:

  1. Thread 1: Fatal error: No ObservableObject of type ArticleBookmarkViewModel found. A View.environmentObject(_:) for ArticleBookmarkViewModel may be missing as an ancestor of this view.
  2. No ObservableObject of type ArticleBookmarkViewModel found. A View.environmentObject(_:) for ArticleBookmarkViewModel may be missing as an ancestor of this view.

CrashReportError: Preview is missing environment object "ArticleBookmarkViewModel"

iNews crashed due to missing environment of type: ArticleBookmarkViewModel. To resolve this add .environmentObject(ArticleBookmarkViewModel(...)) to the appropriate preview.

// Bookmark button Button { toggleBookmark(for: article) } label: { // jika ada Artikel yang di Bookmark maka munculkan icon Bookmark Fil, jika tidak ada maka pakai icon bookmark biasa Image(systemName: articleBookmarkVM.isBookmarked(for: article) ? "bookmark.fill" : "bookmark") }

@dekapd99 dekapd99 added the bug Something isn't working label Jun 7, 2022
@dekapd99
Copy link
Owner Author

dekapd99 commented Jun 8, 2022

Penyebab: kesalahan pemanggilan environment object di root project file iNews.swift, dan di Views files folder ArticleRowView.swift, ArticleListView.swift, dan NewsTabView.swift

Dari code ini di iNews.swift:
@StateObject var articleBookmarkVM = ArticleNewsViewModel()
menjadi
@StateObject var articleBookmarkVM = ArticleBookmarkViewModel()

Dari code ini di ArticleRowView.swift, ArticleListView.swift, dan NewsTabView.swift:
@StateObject static var articleBookmarkVM = ArticleNewsViewModel()
menjadi
@StateObject static var articleBookmarkVM = ArticleBookmarkViewModel()

Hasilnya: Preview Canvas bisa dilakukan dan tidak ada error ketika build & run di ios emulator
Notes: HARUS HATI-HATI KETIKA MEMANGGIL ENVIRONMENT OBJECT

@dekapd99 dekapd99 closed this as completed Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant