This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CAShapeLayer { | |
static func rectangle(roundedRect: CGRect, cornorRadius: CGFloat, color: UIColor) -> CAShapeLayer { | |
let path = UIBezierPath(roundedRect: roundedRect, cornerRadius: cornorRadius) | |
let shape = CAShapeLayer() | |
shape.path = path.cgPath | |
shape.fillColor = color.cgColor | |
return shape | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Date { | |
//2 | |
func convertToMonthYearFormat() -> String { | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "MMM yyyy" | |
return dateFormatter.string(from: self) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func dismissKeyboardGesture() { | |
let tapGesture = UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))) | |
view.addGestureRecognizer(tapGesture) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
let red = UIColor.red | |
let red2 = UIColor.red | |
print(red === red2) // proves this is a flyweight | |
let color = UIColor(red: 1, green: 0, blue: 0, alpha: 1) | |
let color2 = UIColor(red: 1, green: 0, blue: 0, alpha: 1) | |
print(color === color2) // proves this is NOT a flyweight |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// get some dummy json | |
let json = "{'name' : 'john snow'; 'age' : '29'}" | |
// get a reference to upload server | |
let url = URL(string: "https://httpbin.org/post")! | |
var request = URLRequest(url: url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PlaygroundSupport | |
// Declare a session configuration | |
let defaultConfiguration = URLSessionConfiguration.default | |
defaultConfiguration.allowsCellularAccess = true | |
defaultConfiguration.waitsForConnectivity = true | |
// assign that configuration to a session | |
let session = URLSession(configuration: defaultConfiguration) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Testing: UIViewController { | |
let fileManager = FileManager.default | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
if let path = Bundle.main.resourcePath { | |
guard let items = try? fileManager.contentsOfDirectory(atPath: path) else { print("Path is not available"); return } | |
for item in items { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MusicPlayer { | |
init() { | |
print("Music Player has started") | |
} | |
} | |
class Singer { | |