Skip to content

Instantly share code, notes, and snippets.

Aaina Jain aainaj

  • News Technology Services
  • Bangalore, India
Block or report user

Report or block aainaj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aainaj
aainaj / DispatchQueueAsyncTaskRetainCycle.swift
Last active Jan 13, 2020
self in dispatch queue doesn't cause retain cycle
View DispatchQueueAsyncTaskRetainCycle.swift
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
View NotificationCenterRetainCycle.swift
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"
View FunctionAssignmentToClosure.swift
import Foundation
import UIKit
class ListViewController: UIViewController {
var listTitle: (() -> String)?
override func viewDidLoad() {
super.viewDidLoad()
listTitle = makeTitle
}
View ClosureWithoutSelf.swift
import Foundation
import UIKit
class ListViewController: UIViewController {
var listTitle: (() -> String)?
override func viewDidLoad() {
super.viewDidLoad()
View ClosureWithSelf.swift
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 Jun 10, 2019
Count number of lines of uilabel for max height for all screen sizes
View CountLinesForMaxHeightForAllScreenSize.swift
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 Jun 10, 2019
Count number of lines of uilabel for max height
View CountLinesForMaxHeight.swift
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))
View PropertyObserver.swift
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 Apr 22, 2019
Computed property example
View ComputedProperty.swift
import Foundation
struct Rectangle {
var width = 0.0
var height = 0.0
var area: Double {
set {
width = sqrt(newValue)
height = sqrt(newValue)
You can’t perform that action at this time.