Skip to content

Instantly share code, notes, and snippets.

View shabib87's full-sized avatar

Shabib Hossain shabib87

View GitHub Profile
@shabib87
shabib87 / RetainCycle8.swift
Last active March 13, 2017 10:17
In support to blog post
class HTMLElement {
...
lazy var asHTML: () -> String = { [weak self] in
guard let htmlElement = self else { return "" }
return "<\(htmlElement.name)>\(htmlElement.text)</\(htmlElement.name)>"
}
...
}
@shabib87
shabib87 / RetainCycle4.swift
Last active March 13, 2017 10:17
In support to blog post
class Person {
let name: String
var apartment: Apartment?
init(name: String) {
self.name = name
}
deinit {
print("\(name) is being deinitialized")
}
@shabib87
shabib87 / RetainCycle2.swift
Created March 13, 2017 10:16
In support to blog post
class Person {
let name: String
init(name: String) {
self.name = name
}
deinit {
print("\(name) is being deinitialized")
}
}
@shabib87
shabib87 / RetainCycle1.swift
Last active March 10, 2017 19:12
In support to blog post
class Person {
let name: String
init(name: String) {
self.name = name
}
deinit {
print("\(name) is being deinitialized")
}
}
@shabib87
shabib87 / TextViewWithPlaceholderAndExpandingHeight.swift
Last active March 5, 2017 06:11
An UITextFiled like UITextView subclass with placeholder and round border and it updates it's height on text change. The default color for border and placeholder text color are similar with UITextFields.
/*
TextViewWithPlaceholderAndExpandingHeight.swift
TextViewWithPlaceholderAndExpandingHeight
Created by Shabib Hossain on 1/24/17.
Copyright (c) 2017 shabib87 <shabib.sust@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
enum BiriyaniType {
case veg
case nonveg
}
class Biriyani {
let count: Int
let size: OrderSize
let spiceRange: SpiceRange
let type: BiriyaniType
class Biriyani {
let count: Int
let size: OrderSize
let spiceRange: SpiceRange
let type: BiriyaniType
init (count: Int = 1, size: OrderSize = .medium, spiceRange: SpiceRange = .spicy, type: BiriyaniType = .nonveg) {
self.count = count
self.size = size
self.spiceRange = spiceRange
class Biriyani {
let count: Int
let size: OrderSize
let spiceRange: SpiceRange
init (count: Int, size: OrderSize, spiceRange: SpiceRange) {
self.count = count
self.size = size
self.spiceRange = spiceRange
}
enum OrderSize {
case small
case medium
case large
}
enum SpiceRange {
case spicy
case hot
case extraHot
class User {
var name = ""
var age = 0
}
class EditUserInfoController {
var user: User
init (user: User) {
self.user = user