This file contains 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 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 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 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 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 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 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 SwiftUI | |
struct ContentView: View { | |
@State private var orderCount = 0 | |
var body: some View { | |
VStack { | |
// Initializing a Stepper |
This file contains 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 SwiftUI | |
struct ContentView: View { | |
private var isActivatedMessage: String { | |
return "CatNip mode is " + (isActivated ? "Activated" : "Deactivated") | |
} | |
private var dateFormater: DateFormatter { | |
let dateFormater = DateFormatter() |
This file contains 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 SwiftUI | |
struct ContentView: View { | |
@State private var colorChange = false | |
@State private var sizeChange = false | |
var body: some View { | |
VStack(alignment: .center, spacing: 30) { |