Skip to content

Instantly share code, notes, and snippets.

View aainaj's full-sized avatar

Aaina Jain aainaj

  • GoJek Tech
  • Bangalore, India
View GitHub Profile
import UIKit
class ListViewController: UIViewController {
let label = UILabel(frame: CGRect(x: 100, y: 200, width: 300, height: 50))
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
label.text = "Animating"
import Foundation
import UIKit
class ListViewController: UIViewController {
var listTitle: (() -> String)?
override func viewDidLoad() {
super.viewDidLoad()
listTitle = makeTitle
}
import Foundation
import UIKit
class ListViewController: UIViewController {
var listTitle: (() -> String)?
override func viewDidLoad() {
super.viewDidLoad()
import Foundation
import UIKit
class ListViewController: UIViewController {
var listTitle: (() -> String)?
override func viewDidLoad() {
super.viewDidLoad()
listTitle = {
print(self.view.debugDescription)
@aainaj
aainaj / CountLinesForMaxHeightForAllScreenSize.swift
Created June 10, 2019 00:24
Count number of lines of uilabel for max height for all screen sizes
func countLines(of label: UILabel, maxHeight: CGFloat) -> Int {
// viewDidLayoutSubviews() in ViewController or layoutIfNeeded() in view subclass
guard let labelText = label.text else {
return 0
}
let rect = CGSize(width: label.bounds.width, height: maxHeight)
let labelSize = labelText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: label.font!], context: nil)
let lines = Int(ceil(CGFloat(labelSize.height) / label.font.lineHeight))
@aainaj
aainaj / CountLinesForMaxHeight.swift
Last active June 10, 2019 00:22
Count number of lines of uilabel for max height
func countLines(of label: UILabel, maxHeight: CGFloat) -> Int {
// viewDidLayoutSubviews() in ViewController or layoutIfNeeded() in view subclass
guard let labelText = label.text else {
return 0
}
let rect = CGSize(width: label.bounds.width, height: maxHeight)
let labelSize = labelText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: label.font!], context: nil)
return Int(ceil(CGFloat(labelSize.height) / label.font.lineHeight))
final class ViewController: UIViewController {
let containerView = UIView()
let tableView = UITableView()
var dataModel: [String] = ["Jan", "Feb", "March"] {
didSet {
if (dataModel != oldValue) {
tableView.reloadData()
}
}
willSet(newValue) {
@aainaj
aainaj / ComputedProperty.swift
Created April 22, 2019 00:11
Computed property example
import Foundation
struct Rectangle {
var width = 0.0
var height = 0.0
var area: Double {
set {
width = sqrt(newValue)
height = sqrt(newValue)
@aainaj
aainaj / DI-bad-example.swift
Last active February 13, 2019 02:14
Dependency Inversion Bad Example
struct User {
let name: String
let identifier: String
}
final class UserTransaction {
private let dataBase: DataBase
init(dataBase: DataBase) {
self.dataBase = dataBase