Sunday, November 8, 2026
HomeiOS Developmentios - The best way to extract strategies with default parameters from...

ios – The best way to extract strategies with default parameters from struct

[ad_1]

I wrote a struct for inputting log. The tactic within the struct takes default parameters to acquire log info. Now I need to reuse these strategies in different struct. I considered protocol, however the strategies in protocol are usually not allowed to take default parameters. The struct doesn’t enable inheritance. Is there any great way? Thanks

public struct TrackLog: OptionSet {
   public static let drag = TrackLog(rawValue: 1<<0)
   public static let crop = TrackLog(rawValue: 1<<1)
   public static let sound = TrackLog(rawValue: 1<<2)
   public static let thumbnail = TrackLog(rawValue: 1<<3)
   public static let allLog = TrackLog(rawValue: 1111<<0)
   public let rawValue: Int
   public init(rawValue: Int) {
       self.rawValue = rawValue
   }

   /// Strategies I need to reuse in different structs
   public func error(_ log: Any? = nil, file:String = #file, perform:String = #perform, line:Int = #line) {
   /// Output after processing logs
    }

   /// Strategies I need to reuse in different structs
   public func log(_ title: Any? = nil, log: Any? = nil, file:String = #file, perform:String = #perform, line:Int = #line) {
   /// /// Output after processing logs
   }}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments