Skip to content

Instantly share code, notes, and snippets.

View wrapper.swift
// avoid ambiguous position by using wrapper
let wrapper = UIView()
let view = HeaderView()
view.translatesAutoresizingMaskIntoConstraints = false
view.leftAnchor.constraint(equalTo: wrapper.leftAnchor),
view.rightAnchor.constraint(equalTo: wrapper.rightAnchor),
view.topAnchor.constraint(equalTo: wrapper.topAnchor),
view.bottomAnchor.constraint(equalTo: wrapper.bottomAnchor),
View activate.swift
equalTo: guide_mark.leftAnchor,
constant: -8
View addConstraints.swift
// add constraints through Autolayout Visual Format Language
withVisualFormat: "H:|-50-[button]",
options: .alignAllTop,
metrics: nil,
views: objects
View constraints.swift
// UIViewController
let constraints = [
view.centerXAnchor.constraint(equalTo: superview.centerXAnchor),
view.centerYAnchor.constraint(equalTo: superview.centerYAnchor),
view.widthAnchor.constraint(equalTo: superview.widthAnchor)
view.heightAnchor.constraint(equalTo: superview.heightAnchor),
View uiview+extension.h
/// UIView.h
@class NSLayoutXAxisAnchor,NSLayoutYAxisAnchor,NSLayoutDimension;
@interface UIView (UIViewLayoutConstraintCreation)
/* Constraint creation conveniences. See NSLayoutAnchor.h for details.
@property(nonatomic,readonly,strong) NSLayoutXAxisAnchor *leadingAnchor API_AVAILABLE(ios(9.0));
@property(nonatomic,readonly,strong) NSLayoutXAxisAnchor *trailingAnchor API_AVAILABLE(ios(9.0));
// more anchors...
""" File:
An lldb Python script to add a nudge command.
Add to ~/.lldbinit:
command script import ~/path/to/
(lldb) nudge x-offset y-offset [view]
View PurePerson.swift
class Person {
var age: Int
init(age: Int) {
self.age = age
View Person.swift
class Person: NSObject {
@objc dynamic var age: Int
init(age: Int) {
self.age = age
View NSKeyValueObserverRegistration.h
@interface NSObject(NSKeyValueObserverRegistration)
/* Register or deregister as an observer of the value at a key path relative to the receiver.
The options determine what is included in observer notifications and when they're sent, as described above,
and the context is passed in observer notifications as described above. You should use
-removeObserver:forKeyPath:context: instead of -removeObserver:forKeyPath: whenever possible because it allows
you to more precisely specify your intent. When the same observer is registered for the same key path multiple times,
but with different context pointers each time, -removeObserver:forKeyPath: has to guess at the context pointer when
deciding what exactly to remove, and it can guess wrong.
- (BOOL)shouldAutorotate {
return NO;
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);