GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

Day 59 - Challenge 3

Forums > 100 Days of SwiftUI

@SD449  

Hi

Can someone point me in the right direction on how to tackle Challenge 3 on Day 59; Modify the predicate string parameter to be an enum such as .beginsWith, then make that enum get resolved to a string inside the initializer.

So far all I have is;

    enum predicateParameter {
        case beginsWith
    }

I tried inserting this into the init and then tried adding a function and adding that to the init but neither worked.

To be honest I am not sure I really understand the premise of the challenge, hence a pointer to get me started would be much appreciated.

Thank You

3      

I was also struggling with the premise but in order to clarify the purpose of the challenge I simplified it for myself a lil bit. Instead of an enum, I made an array with the predicate parameters as so:

let parameters = ["BEGINSWITH", "ENDSWITH", "CONTAINS[c]"]

Then I edited the predicate in the FilteredList initializer to this, where 'psp' was an Int selected by a Picker in ContentView:

NSPredicate(format: "%K \(parameters[psp]) %@", filterKey, filterValue)

This allowed me to sort the names based on the aforementioned parameters <3

3      

You have to use raw values!

enum PredicateType: String {
    case beginsWith = "BEGINSWITH"
    case contains = "CONTAINS"
    case containsCI = "CONTAINS[c]"
}

Then you can use the string values in this way

PredicateType.beginsWith.rawValue

3      

Hacking with Swift is sponsored by try! Swift Tokyo.

SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!

Get your ticket here

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.