func makeImage() -> UIImage? {
    if let im = UIImage(named:"myImage") {
        return im
    }
    return nil
}



func test() {
    let path = Bundle.main.path(forResource:"001", ofType: "png")!
    for j in 0 ..< 50 {
        for i in 0 ..< 100 {
            let im = UIImage(contentsOfFile: path)
        }
    }
}



func test() {
    let path = Bundle.main.path(forResource:"001", ofType: "png")!
    for j in 0 ..< 50 {
        autoreleasepool {
            for i in 0 ..< 100 {
                let im = UIImage(contentsOfFile: path)
            }
        }
    }
}



class ColorPickerController : UIViewController {
    weak var delegate: ColorPickerDelegate?
    // …
}



var observers = Set<NSObject>()
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    let ob = NotificationCenter.default.addObserver(
        forName: .woohoo, object:nil, queue:nil) { _ in
            print(self.description) // Szykują się problemy…
         }
    self.observers.insert(ob as! NSObject)
}



override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
    for ob in self.observers {
        NotificationCenter.default.removeObserver(ob)
    }
}



let ob = NotificationCenter.default.addObserver(
    forName: .woohoo, object:nil, queue:nil) { [unowned self] _ in
        print(self.description)
    }



for ob in self.observers {
    NotificationCenter.default.removeObserver(ob)
}
self.observers.removeAll()



var obs = Set<NSKeyValueObservation>()
func registerWith(_ mc:MyClass1) {
    let opts : NSKeyValueObservingOptions = [.old, .new]
    let ob = mc.observe(\.value, options: opts) { obj, change in
        print(self) // Wyciek pamięci!
    }
    obs.insert(ob)
}



var timer : Timer!
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.timer = Timer.scheduledTimer(timeInterval: 1, target: self,
        selector: #selector(fired), userInfo: nil, repeats: true)
    self.timer.tolerance = 0.1
}
@objc func fired(_ t:Timer) {
    print("Licznik czasu został wyzwolony.")
}
override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
    self.timer.invalidate()
}



var timer : Timer!
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) {
        [unowned self] t in // *
        self.fired(t)
    }
    self.timer.tolerance = 0.1
}
func fired(_ t:Timer) {
    print("Licznik czasu został wyzwolony.")
}
deinit {
    self.timer.invalidate()
}



let con = UIGraphicsGetCurrentContext()!
let locs : [CGFloat] = [ 0.0, 0.5, 1.0 ]
let colors : [CGFloat] = [
    0.8, 0.4, // Kolor początkowy: przezroczysty jasnoszary.
    0.1, 0.5, // Kolor pośredni: ciemniejszy i mniej przezroczysty szary.
    0.8, 0.4, // Kolor końcowy: przezroczysty jasnoszary.
]
let sp = CGColorSpaceCreateDeviceGray()
let grad = CGGradient(colorSpace: sp,
    colorComponents: colors, locations: locs, count: 3)!
con.drawLinearGradient(grad,
    start: CGPoint(x:89,y:0), end: CGPoint(x:111,y:0), options:[])



class StringDrawer {
    @NSCopying var attributedString : NSAttributedString!
    // …
}



class StringDrawer {
    @NSCopying var attributedString : NSAttributedString!
    private var mutableAttributedString : NSMutableAttributedString! {
        get {
            if self.attributedString == nil {return nil}
            return NSMutableAttributedString(
                attributedString:self.attributedString)
        }
        set {
            self.attributedString = newValue
        }
    }
    // …
}







