Post

Replies

Boosts

Views

Activity

Swift Protocol Constraint Required - Advanced
Please help me with this, I need to put a protocol requirement constraint somewhere in my code but I don’t know where Business case: A generic filter manager class that can manage a list of filters A filter is defined by a protocol, the filter specification should have the field type (string, int, date …) and the array type, the filter class implementing the protocol will be responsible to extract the distinct value from that array protocol SimpleFilter {     associatedtype ArrayType: Collection     associatedtype ValueType: Comparable     var values: [ValueType] { get set }     func extractValues(from array: ArrayType) } let’s define an object type for the array we would like to filter as an example struct City {     let code: String     let country: String     let region: String } An array of cities could be filtered by country & region, we will define 2 filter fields class CountryFilter: SimpleFilter {     var values = [String]()     func extractValues(from array: [City]) {         // remove duplicates     } } class RegionFilter: SimpleFilter {     var values = [String]()     func extractValues(from array: [City]) {         // remove duplicates     } } with Swift 5.7 we can now use Any to store these filters in the same array let filters: [any SimpleFilter] = [CountryFilter(), RegionFilter()] Now we need to build a filter manager, this filter manager will accept a generic array to be filtered and the filter fields, a protocol requirement is required on the Array Type I guess, this is where I need help ... in the initializer, I would like to unbox SimpleFilter and pass it the generic array but it does not work class FiltersManager<T: Collection> {     private var originalArray: T     private var filteredArray: T     private(set) var filters: [any SimpleFilter]     public init(array: T, filters: [any SimpleFilter]) {         self.originalArray = array         self.filteredArray = array         self.filters = filters         for filter in filters {             //filter.extractValues(from: array) <— Missing a constraint here         }     } } I tried something like this but it does not work either class TestFiltersManager<T: Collection, F: SimpleFilter> where F.ArrayType == T { thanks for help alex
6
0
1.2k
Oct ’22
Apple Music - No Results for "Artist" try again
With the recent macOS update 11.2.2 Apple Music on my mac mini (M1) search function does not work if I type any artist in the search bar (select the scope button Apple Music) hit enter I got the message No Results for "the artist searched" however while typing the artist name, if you click on the suggestion in the auto-complete, it works I tested the same functionalities with my MacBook Pro 2016 and it works, looks like something related to the M1 version, it was also working in previous version like (macOS 11.2) thanks
3
0
1.8k
Mar ’21
SwiftUI presentationMode dismiss not work on specific case
I am presenting a sheet using the view modifier .sheet(item: ...) if the view you are presenting is wrap inside another view which only add a navigation view let's say I have a view called ViewB with a dismiss button which called the presentation mode dismiss, that works let' say I have another view called ViewBWithNavigationView where it's calling ViewB inside the NavigationView and it also calling dismiss on the cancel button the result of this is that the presentation mode dismiss will only works for the first view B the cancel button, it will no close the view if you click the button inside the view struct ViewBInsideNavigationView: View {       @Environment(\.presentationMode) var presentationMode   var body: some View {     NavigationView {       ViewB()         .navigationBarTitle("View B", displayMode: .inline)         .navigationBarItems(leading: Button("Cancel") {           self.presentationMode.wrappedValue.dismiss()         })     }   } } the call to self.presentationMode.wrappedValue.dismiss() inside ViewB is not trigger and the view is not dismiss thanks
12
0
16k
Aug ’20
SwfitUI impossible working with 2 NavigationView
Working with more than 1 UINavigationController is pretty common in a UIKit app by example, you could have one navigation controller for an on boarding process to finally arrive to a main menu like a UITabBarController where each tab is embedded in it's own navigation controller however it's not possible in SwiftUI when you push a view where your destination view has it's own NavigationView, you will have 2 navigation bar embedded it's that a bug or the expected behaviour? thanks
0
0
431
Jun ’20
NSPersistentHistoryChange value changed
I am trying to know the value that was changed in the history, however after getting the transaction,after getting the NSPersistentHistoryChangefrom the transaction.changes SETthe changes only give us a SET of updated properties, you don't know from which the old &amp; new value in that time ...you only have the changed object id and that will give you the current value ...if you have 2 transactions that change the same entity, same fieldit's impossible to know what was the value of the field in transaction 1please help, that looks like a big omission thanks
0
1
556
Mar ’20
IPA Processing Failed
Not sure if something changed recently or today, but as of today, our App with Automatic Signing (where the profile is managed by Apple) can't be archived, it used to works, same piece of code on the same git branchnow we got an error message saying IPA Processing Failed ...on the Signing &amp; Capabilities, when we click on the little i next to the provisioning profile, we can see the iOS Team Provisioning Profile is selected correctly ...but when archiving, it can't find it, it propose the wildcard profilethanks
1
0
1.9k
Jan ’20