Post

Replies

Boosts

Views

Activity

Reply to So @Apple - What're you going to do with the ongoing spam & consumers being able to post here
All it takes is determining if there is a paid contract on file, no spammer is going to mess with having to pay for and losing an account each time due to the cost and it allows apple to enforce the rules more. No paid contract on file then read only access is provided. As for students validate them via their institution id numbers, parents where needed or a student paid contract. This will prevent furious consumers from posting here as well.
Oct ’22
Reply to Swift Protocol Constraint Required - Advanced
Don't use any as you have no use case for it. class FiltersManager<T: Collection, U: SimpleFilter> where T == U.ArrayType {     private var originalArray: T     private var filteredArray: T     private(set) var filters: [U]     public init(array: T, filters: [U]) {         self.originalArray = array         self.filteredArray = array         self.filters = filters         for filter in filters {             filter.extractValues(from: array)         }     } }
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’22
Reply to Swift Protocol Constraint Required - Advanced
Or if you really need to use any then just apply it to the filter property. class FiltersManager<T: Collection, U: SimpleFilter> where T == U.ArrayType {     private var originalArray: T     private var filteredArray: T     private(set) var filters: [any SimpleFilter]     public init(array: T, filters: [U]) {         self.originalArray = array         self.filteredArray = array         self.filters = filters         for filter in filters {             filter.extractValues(from: array)         }     } }
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’22
Reply to Swift Protocol Constraint Required - Advanced
This is what I had to do in the end. Each filter had to be cast to its concrete type to call or access any property or method. protocol SimpleFilter {     associatedtype ArrayType: Collection     associatedtype ValueType: Comparable     var values: [ValueType] { get set }     func extractValues(from array: ArrayType) } extension SimpleFilter {     func extractValues(from array: [City]) {         print(array.count, values.count)     } } struct City {     let code: String     let country: String     let region: String } struct CountryFilter: SimpleFilter {     var values: [String]          typealias ArrayType = [City]     typealias ValueType = String } struct RegionFilter: SimpleFilter {     var values: [String]          typealias ArrayType = [City]     typealias ValueType = String } typealias anySimpleFilter = any SimpleFilter class FiltersManager<T: Collection> {          private var originalArray: T     private var filteredArray: T     private(set) var filters: [anySimpleFilter]          public init(array: T, filters: [anySimpleFilter]) {         self.originalArray = array         self.filteredArray = array         self.filters = filters                  for filter in filters {             if let filter = filter as? CountryFilter {                 filter.extractValues(from: array as! [City])             } else if let filter = filter as? RegionFilter {                 filter.extractValues(from: array as! [City])             }         }              } } let filters = [RegionFilter(values: []), CountryFilter(values: [])] as [any SimpleFilter] let cities = [City(code: "0", country: "CA", region: "NA")] let manager = FiltersManager(array: cities, filters: filters)
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’22
Reply to Swift Protocol Constraint Required - Advanced
A much simpler approach: protocol ProtocolThing {     associatedtype Item     var values: Item { get set }     func things() -> Item } struct Thing1: ProtocolThing {     typealias Item = String     var values: Item     func things() -> Item {         values     } } struct Thing2: ProtocolThing {     typealias Item = String     var values: Item     func things() -> Item {         values     } } struct Doctor {     var things: [any ProtocolThing]     func thingAMeJig() -> String {         let thing = things[Int.random(in: 0..<things.count)]         return "\(thing.values) - \(thing.things())"     } } let exam = Doctor(things: [Thing1(values: "Hat"), Thing2(values: "Cat")]) print(exam.thingAMeJig())
Topic: Programming Languages SubTopic: Swift Tags:
Oct ’22
Reply to Swift Protocol Constraint Required - Advanced
Here is my version minus the manual abstraction allowing the any keyword to do what it was meant to do. We define a protocol for the data model, City, allowing it to participate in the compiler's existential abstraction. Runs without issue. import Cocoa public protocol ManagedFilter: AnyObject {     typealias Condition = ((any DataModel) -> Bool)     var name: String { get }     var condition: Condition? { get }     func extractValues(from array: [any DataModel]) } public protocol FilterSpecification: ManagedFilter {     associatedtype ValueType: Comparable     var values: [ValueType] { get set } } public protocol DataModel {     var code: String { get }     var country: String { get }     var region: String { get } } public class FiltersManager {     private var originalArray: [any DataModel]     private var filteredArray: [any DataModel]     private(set) var filters: [any FilterSpecification]     public init(array: [any DataModel], filters: [any FilterSpecification]) {         self.originalArray = array         self.filteredArray = array         self.filters = filters         self.filters.forEach {             $0.extractValues(from: array)         }     } } struct City1: DataModel {     let code: String     let country: String     let region: String } struct City2: DataModel {     let code: String     let country: String     let region: String } class CountryFilter1: FilterSpecification {     var name = "Country"     var values = [String]()     var condition: ((any DataModel) -> Bool)? {         guard !values.isEmpty else { return nil }         return { city in             self.values.contains(city.country)         }     }     func extractValues(from array: [any DataModel]) {         // remove duplicates     } } class RegionFilter1: FilterSpecification {     var name = "Region"     var values = [String]()     var condition: ((any DataModel) -> Bool)? {         guard !values.isEmpty else { return nil }         return { city in             self.values.contains(city.region)         }     }     func extractValues(from array: [any DataModel]) {         // remove duplicates     } } let cities = [City1(code: "001", country: "US", region: "EST"), City2(code: "002", country: "CA", region: "MST")] let manager = FiltersManager(array: cities, filters: [CountryFilter1(), RegionFilter1()])
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’22
Reply to [MyClass initWithCoder:]: unrecognized selector sent to instance - On iOS16
The correct pattern for calling initWithCoder as an instance method and not a class method, which doesn't exist provided you didn't create a class version of the method, is [[MyClass alloc] initWithCoder: aCoder]. And what the error above is telling you is the variable or property result points to nothing. Always perform a NULL check on the result before passing it to unarchiveObjectWithData:.
Topic: App & System Services SubTopic: General Tags:
Nov ’22
Reply to WeatherKit returning blank response
Then the API limits have been exceeded.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to Widgetkit | Connection Issue on Real Device
If using an actual device, ensure the internet is accessible via WIFI or Data, the request is using SSL, and the hostname is resolvable.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to So @Apple - What're you going to do with the ongoing spam & consumers being able to post here
All it takes is determining if there is a paid contract on file, no spammer is going to mess with having to pay for and losing an account each time due to the cost and it allows apple to enforce the rules more. No paid contract on file then read only access is provided. As for students validate them via their institution id numbers, parents where needed or a student paid contract. This will prevent furious consumers from posting here as well.
Replies
Boosts
Views
Activity
Oct ’22
Reply to iOS16 Widget Lock Screen show sensitive information even if .privacySensitive() is set
Try adjusting the visibility options for the same widget in the phone settings maybe under privacy and see of the code honors the logic.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to SwiftUI is crashing when changing the tabs
Show us code instead pretty much what you're doing.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to Swift Protocol Constraint Required - Advanced
Don't use any as you have no use case for it. class FiltersManager<T: Collection, U: SimpleFilter> where T == U.ArrayType {     private var originalArray: T     private var filteredArray: T     private(set) var filters: [U]     public init(array: T, filters: [U]) {         self.originalArray = array         self.filteredArray = array         self.filters = filters         for filter in filters {             filter.extractValues(from: array)         }     } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to Swift Protocol Constraint Required - Advanced
Or if you really need to use any then just apply it to the filter property. class FiltersManager<T: Collection, U: SimpleFilter> where T == U.ArrayType {     private var originalArray: T     private var filteredArray: T     private(set) var filters: [any SimpleFilter]     public init(array: T, filters: [U]) {         self.originalArray = array         self.filteredArray = array         self.filters = filters         for filter in filters {             filter.extractValues(from: array)         }     } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to Swift Protocol Constraint Required - Advanced
This is what I had to do in the end. Each filter had to be cast to its concrete type to call or access any property or method. protocol SimpleFilter {     associatedtype ArrayType: Collection     associatedtype ValueType: Comparable     var values: [ValueType] { get set }     func extractValues(from array: ArrayType) } extension SimpleFilter {     func extractValues(from array: [City]) {         print(array.count, values.count)     } } struct City {     let code: String     let country: String     let region: String } struct CountryFilter: SimpleFilter {     var values: [String]          typealias ArrayType = [City]     typealias ValueType = String } struct RegionFilter: SimpleFilter {     var values: [String]          typealias ArrayType = [City]     typealias ValueType = String } typealias anySimpleFilter = any SimpleFilter class FiltersManager<T: Collection> {          private var originalArray: T     private var filteredArray: T     private(set) var filters: [anySimpleFilter]          public init(array: T, filters: [anySimpleFilter]) {         self.originalArray = array         self.filteredArray = array         self.filters = filters                  for filter in filters {             if let filter = filter as? CountryFilter {                 filter.extractValues(from: array as! [City])             } else if let filter = filter as? RegionFilter {                 filter.extractValues(from: array as! [City])             }         }              } } let filters = [RegionFilter(values: []), CountryFilter(values: [])] as [any SimpleFilter] let cities = [City(code: "0", country: "CA", region: "NA")] let manager = FiltersManager(array: cities, filters: filters)
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to Swift Protocol Constraint Required - Advanced
A much simpler approach: protocol ProtocolThing {     associatedtype Item     var values: Item { get set }     func things() -> Item } struct Thing1: ProtocolThing {     typealias Item = String     var values: Item     func things() -> Item {         values     } } struct Thing2: ProtocolThing {     typealias Item = String     var values: Item     func things() -> Item {         values     } } struct Doctor {     var things: [any ProtocolThing]     func thingAMeJig() -> String {         let thing = things[Int.random(in: 0..<things.count)]         return "\(thing.values) - \(thing.things())"     } } let exam = Doctor(things: [Thing1(values: "Hat"), Thing2(values: "Cat")]) print(exam.thingAMeJig())
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to New App Store Review Guideline - 3.1.1 In-App Purchase
My suggestion would be to consult an attorney and see what your options are if affected.
Topic: App & System Services SubTopic: StoreKit Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Unboxing protocol to concrete type in SwiftUI View
struct RowView: View {     var item: any ItemProtocol     init(item: any ItemProtocol) {         self.item = item     }     var body: some View {         Text("Row View")     } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Swift Protocol Constraint Required - Advanced
Here is my version minus the manual abstraction allowing the any keyword to do what it was meant to do. We define a protocol for the data model, City, allowing it to participate in the compiler's existential abstraction. Runs without issue. import Cocoa public protocol ManagedFilter: AnyObject {     typealias Condition = ((any DataModel) -> Bool)     var name: String { get }     var condition: Condition? { get }     func extractValues(from array: [any DataModel]) } public protocol FilterSpecification: ManagedFilter {     associatedtype ValueType: Comparable     var values: [ValueType] { get set } } public protocol DataModel {     var code: String { get }     var country: String { get }     var region: String { get } } public class FiltersManager {     private var originalArray: [any DataModel]     private var filteredArray: [any DataModel]     private(set) var filters: [any FilterSpecification]     public init(array: [any DataModel], filters: [any FilterSpecification]) {         self.originalArray = array         self.filteredArray = array         self.filters = filters         self.filters.forEach {             $0.extractValues(from: array)         }     } } struct City1: DataModel {     let code: String     let country: String     let region: String } struct City2: DataModel {     let code: String     let country: String     let region: String } class CountryFilter1: FilterSpecification {     var name = "Country"     var values = [String]()     var condition: ((any DataModel) -> Bool)? {         guard !values.isEmpty else { return nil }         return { city in             self.values.contains(city.country)         }     }     func extractValues(from array: [any DataModel]) {         // remove duplicates     } } class RegionFilter1: FilterSpecification {     var name = "Region"     var values = [String]()     var condition: ((any DataModel) -> Bool)? {         guard !values.isEmpty else { return nil }         return { city in             self.values.contains(city.region)         }     }     func extractValues(from array: [any DataModel]) {         // remove duplicates     } } let cities = [City1(code: "001", country: "US", region: "EST"), City2(code: "002", country: "CA", region: "MST")] let manager = FiltersManager(array: cities, filters: [CountryFilter1(), RegionFilter1()])
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to Xcode 14.0.1, Build time Slow as Hell!
Or it is just your project and its dependencies.
Replies
Boosts
Views
Activity
Nov ’22
Reply to [MyClass initWithCoder:]: unrecognized selector sent to instance - On iOS16
The correct pattern for calling initWithCoder as an instance method and not a class method, which doesn't exist provided you didn't create a class version of the method, is [[MyClass alloc] initWithCoder: aCoder]. And what the error above is telling you is the variable or property result points to nothing. Always perform a NULL check on the result before passing it to unarchiveObjectWithData:.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to macOS 10.12.4 NSButton After adding CAGradientLayer, button title is not displayed
Maybe because you're hiding the label by placing the new layer at index 0. Find the Label layer index and insert the gradient beneath it.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Nov ’22