Post

Replies

Boosts

Views

Activity

Comment on Swift Protocol Constraint Required - Advanced
Hi, thanks, sorry for delay, I really appreciated the help, but the goal is to have a generic FilterManager class, I don't want to use casting inside the init ... I found a way to do it (without using ANY, but I am sure with Swift 5.7 there is a better way to do it) ... I will share it you, give me 1-2 days and I will drop the code here.
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’22
Comment on Swift Protocol Constraint Required - Advanced
thanks but it does not work, the code compiles ok but if you try to instantiate the FiltersManager class you will have an error you can't pass an array of type Any SimpleFilter to filters typed as [U] in the class initializer Compiler error: Type 'any SimpleFilter' cannot conform to 'SimpleFilter' try this you will see let filters: [any SimpleFilter] = [CountryFilter(), RegionFilter()] var cities = [City]() let manager = TestFiltersManager(array: cities, filters: filters)
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’22
Comment on Swift Protocol Constraint Required - Advanced
the problem is that your DataModel is a protocol here, the FilterManager class should be generic and accept any kind of array ... I want to be able to reuse the filter manager class
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’22
Comment on Swift Protocol Constraint Required - Advanced
Hi, thanks, sorry for delay, I really appreciated the help, but the goal is to have a generic FilterManager class, I don't want to use casting inside the init ... I found a way to do it (without using ANY, but I am sure with Swift 5.7 there is a better way to do it) ... I will share it you, give me 1-2 days and I will drop the code here.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’22
Comment on Swift Protocol Constraint Required - Advanced
thanks, but it does not help, I am still where I was ... something is missing to be able to unbox the filter and pass it the generic array ... I will create a playground and post the GitHub URL
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Oct ’22
Comment on Swift Protocol Constraint Required - Advanced
thanks but it does not work, the code compiles ok but if you try to instantiate the FiltersManager class you will have an error you can't pass an array of type Any SimpleFilter to filters typed as [U] in the class initializer Compiler error: Type 'any SimpleFilter' cannot conform to 'SimpleFilter' try this you will see let filters: [any SimpleFilter] = [CountryFilter(), RegionFilter()] var cities = [City]() let manager = TestFiltersManager(array: cities, filters: filters)
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Oct ’22