Posts

Important extensions while create a new App in swift

protocol Supporter {     var isEmptyValue : Bool { get }     var isNotEmptyValue : Bool { get } } protocol DecimalSupporter {     var isNegative : Bool { get }     var isPositive : Bool { get } } protocol DoubleSupporter {     var toDouble : Double { get } } protocol FloatSupporter {     var toFloat : Float { get } } protocol IntSupporter {     var toInt : Int { get } } protocol StringSupporter {     var toString : String { get } } protocol DateSupporter {     var toDate : Date ? { get } } protocol DateWithFormateSupporter {     func toDate ( _ formate: String )-> Date ? } extension String : Supporter , DoubleSupporter , FloatSupporter , IntSupporter , DateSupporter , DateWithFormateSupporter {          var toDate : Date ? {         let dateFormatter = DateFormatter ()         return dateFormatter. date ( from : self )     }          func toDate ( _ formate: String ) -> Date ? {         let dateFormatter = DateFormatter ()      

S.O.L.I.D. Principles with Example (Swift & Dart)

  S.O.L.I.D. Principles To create understandable, readable, and testable code that many developers can collaboratively work on. The following five concepts make up our SOLID principles: S ingle Responsibility O pen/Closed L iskov Substitution I nterface Segregation D ependency Inversion 1. Single Responsibility Principle A class should have one and only one reason to change, meaning that a class should have only one job. Problem:  class Invoice {     let String: Book     let price: Float     let quantity: Int     let discountRate: Int     let taxRate: Float     var total: Float = 0.0          init(book: Book, price: Float, quantity: Int, discountRate: Int, taxRate: Float) {         self.book = book     Self.price = price         self.quantity = quantity         self.discountRate = discountRate         self.taxRate = taxRate         self.total = self.calculateTotal()     }     public func calculateTotal() -> Float {         let price = ((book.price - book.price * discountRate) * qu