In Java, I use static block to execute some code when the class is called like in this example"
Class Name
 {
     static
     {
         for(int i = 0; i<10; i++)
         {
         }
     } 
 }
How do I translate that code in Swift?
You could do something like this,.
class SomeViewController : UIViewController {
    public static let formatter: DateFormatter = {
        let df = DateFormatter()
        df.dateFormat = "yyyy-MM-dd"
        return df
    }()
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With