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
class User: Codable { | |
static let shared = User() | |
var hasBeenUpdated = false | |
var completedTasks: Int = 0 | |
var currentlyViewingTask: Int = 0 | |
var milestoneNumber: Int = 0 | |
var totalMilestones: Int = 0 | |
var milestones: [Int] = [1,2,5,10,20,40] | |
var canEdit: Bool = false |
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
class UITextFieldPadded: UITextField { | |
var textPadding = UIEdgeInsets( | |
top: 5, | |
left: 10, | |
bottom: 5, | |
right: 10) | |
override func textRect(forBounds bounds: CGRect) -> CGRect { | |
let rect = super.textRect(forBounds: bounds) |
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
class UILabelPadded: UILabel { | |
var textEdgeInsets = UIEdgeInsets( | |
top: 5, | |
left: 10, | |
bottom: 5, | |
right: 10) | |
open override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect { | |
let insetRect = bounds.inset(by: textEdgeInsets) |
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 | |
class HomeViewController: UIViewController, UITextFieldDelegate { | |
let style = UITraitCollection().userInterfaceStyle | |
var textField: UITextField = { | |
let textField = UITextField() | |
textField.translatesAutoresizingMaskIntoConstraints = false | |
textField.backgroundColor = .systemBackground |
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 Foundation | |
struct AnyStruct { | |
func isUserEligible(age: Int, city: String, income: Int, educationLevel: String) { | |
let isAgeElig: Bool = age >= 18 | |
let isCityElig: Bool = city == "New York" || city == "Los Angeles" || city == "Miami" | |
let isIncomeElig: Bool = income >= 40_000 && income <= 100_000 | |
let isEduLevelElig: Bool = educationLevel == "Bachelors" || educationLevel == "Masters" |
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 DataPoint { | |
let value: Double | |
} | |
struct LineChartShape: Shape { | |
let dataPoints: [DataPoint] | |
let pointSize: CGFloat |
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 Foundation | |
class Solution { | |
func romanToInt(_ s: String) -> Int { | |
var stringVar = s | |
print("stringVar: \(stringVar)") | |
var num = 0 | |
let validDic = [ |
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
class AnyClass { | |
func restApiPostRequest() { | |
let url = URL(string: "https://reqres.in/api/users")! | |
var request = URLRequest(url: url) | |
request.httpMethod = "POST" | |
request.addValue("application/json", forHTTPHeaderField: "Content-Type") | |
let userData = ["name": "John", "position": "Software Engineer", "age": "37"] | |
do { let jsonData = try JSONSerialization.data(withJSONObject: userData, options: .prettyPrinted) | |
request.httpBody = jsonData } |
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 | |
class HomeViewController: UIViewController { | |
var textField: UITextFieldPadded = { | |
let textField = UITextFieldPadded() | |
textField.translatesAutoresizingMaskIntoConstraints = false | |
textField.placeholder = "Enter some text here" | |
return textField }() |
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
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
self.checkMemoryUsage(self.tableView) } | |
func checkMemoryUsage<R>(_ thingToCheck: R, name: String = #function) { | |
// You can pass in almost anything - a variable/constant/struct/class/function etc. | |
let size = MemoryLayout.size(ofValue: thingToCheck) | |
let stride = MemoryLayout.stride(ofValue: thingToCheck) | |
let alignment = MemoryLayout.alignment(ofValue: thingToCheck) |
OlderNewer