This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func pureLayout() { | |
scrollView.autoPinEdgesToSuperviewEdges(with: .zero) | |
scrollView.autoPinEdge(.bottom, to: .bottom, of: longer, withOffset: 20) | |
box.autoPinEdge(toSuperviewEdge: .top, withInset: 150) | |
box.autoAlignAxis(toSuperviewAxis: .vertical) | |
box.autoSetDimensions(to: CGSize(width: 100, height: 100)) | |
circle.autoPinEdge(.bottom, to: .bottom, of: self.view, withOffset: -20, relation: .lessThanOrEqual) | |
circle.autoPinEdge(.bottom, to: .top, of: longer, withOffset: -20, relation: .lessThanOrEqual) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func pureLayout() { | |
scrollView.autoPinEdgesToSuperviewEdges(with: .zero) | |
scrollView.autoPinEdge(.bottom, to: .bottom, of: longer, withOffset: 20) | |
box.autoPinEdge(toSuperviewEdge: .top, withInset: 50) | |
box.autoPinEdge(.left, to: .left, of: self.view, withOffset: 20) | |
box.autoSetDimensions(to: CGSize(width: 100, height: 100)) | |
circle.autoPinEdge(.top, to: .top, of: box) | |
circle.autoPinEdge(.right, to: .right, of: self.view, withOffset: -20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func pureLayout() { | |
box.autoPinEdge(toSuperviewEdge: .top, withInset: 50) | |
box.autoPinEdge(toSuperviewEdge: .left, withInset: 20) | |
box.autoSetDimensions(to: CGSize(width: 100, height: 100)) | |
circle.autoPinEdge(.top, to: .top, of: box) | |
circle.autoPinEdge(toSuperviewEdge: .right, withInset: 20) | |
circle.autoSetDimensions(to: CGSize(width: 100, height: 100)) | |
longer.autoPinEdge(toSuperviewEdge: .left, withInset: 20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// weak reference, but we bet that self will not be nil | |
disposables += signal.observe {[unowned self] values in | |
self.workWithMeAllTheTime() | |
} | |
// weak reference, but self becomes optional | |
disposables += signal.observe {[weak self] values in | |
guard let strongSelf = self else { return } | |
strongSelf.workWithMeAllTheTime() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var disposables = CompositeDisposable() | |
disposables += viewModel.criticalInfo.observeValues {[unowned self] (value) in | |
// react to value | |
} | |
deinit { | |
disposables.dispose() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// public variable accessible from outside of class | |
var producer: SignalProducer<String, NoError> | |
init() { | |
producer = SignalProducer {[weak self] observer, compositeDisposable in | |
guard let strongSelf = self else { return } | |
compositeDisposable.add { | |
print("I've been disposed! I can clean my resources ;)") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var disposables = CompositeDisposable() | |
disposables += viewModel.criticalInfo.observeValues {[unowned self] (value) in | |
// react to value | |
} | |
deinit { | |
disposables.dispose() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let contactTextField = UITextField() | |
contactTextField.delegate = self | |
func textFieldShouldBeginEditing(textField: UITextField) -> Bool { | |
displayContacts() | |
return false // don't start editing | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func contactPicker(picker: CNContactPickerViewController, didSelectContactProperty contactProperty: CNContactProperty) { | |
let contact = contactProperty.contact | |
if let phoneNumber = contact.phoneNumbers.first { // We display only phone numbers, so we will have it ;) | |
let phoneNumberValue = phoneNumber.value as! CNPhoneNumber | |
let result = phoneNumberValue.stringValue | |
self.contactTextField.text = result | |
} else { | |
self.contactTextField.text = ":(" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func displayContacts() { | |
let contactPicker = CNContactPickerViewController() | |
contactPicker.delegate = self // we want to take a contact after coming back | |
contactPicker.displayedPropertyKeys = [CNContactPhoneNumbersKey] // We are interested in phone numbers | |
presentViewController(contactPicker, animated: true, completion: nil) | |
} |