Skip to content

Instantly share code, notes, and snippets.

@jhoughjr
Created November 10, 2020 15:42
Show Gist options
  • Save jhoughjr/1e07c78b9b99d0abeef00ab54d340465 to your computer and use it in GitHub Desktop.
Save jhoughjr/1e07c78b9b99d0abeef00ab54d340465 to your computer and use it in GitHub Desktop.
but you don't
jimmyToday at 9:29 AM
yeah
having more type weirdness
ive got a dict keyed with enum types and its values are my filter functions
their sig is (Meme) -> Bool
when i try say
let fieldFilters = [Meme.SearchableFields.text: memeTextFilter,
Meme.SearchableFields.keywords: memeKeywordsFilter]
private func currrentMemes() -> [Meme] {
let f = fieldFilters[searchedField]
return memes.filter(f as! (Meme) -> Bool)
}
that will compile but if i remove the forced cast it says always fails, i get confusing results
i get
Cannot convert value of type '((MemeListView) -> (Meme) -> Bool)?' to expected argument type '(FetchedResults<Meme>.Element) throws -> Bool' (aka '(Meme) throws -> Bool')
i dont see where it thinks MemeListView is part of any signature involved
i guess i havent tried speccifiying the type in the declaration...
ok so speccifying the type makes "Type of expression is ambiguous without more context" wow.
let fieldFilters:[Meme.SearchableFields: (Meme) -> Bool] = [Meme.SearchableFields.text: memeTextFilter,
Meme.SearchableFields.keywords: memeKeywordsFilter]
this makjes zero sense.
and if I do this
@State var fieldFilters:[Meme.SearchableFields: ((Meme) -> Bool)]
private func currrentMemes() -> [Meme] {
fieldFilters = [.text: memeTextFilter,
.keywords: memeKeywordsFilter]
let f = fieldFilters[searchedField]
return memes.filter(f!)
}
builds fine. I can't even even anymore.
exact same signature.
which also ties back to .popover vs .sheet with the exact same signature behaving completely differently
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment