This file contains hidden or 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
| // Chapter 1: Introducing Auto Layout | |
| // Chapter 2: Construct Auto Layout with the Interface Builder | |
| // 1 | |
| override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { | |
| view.addSubview(contactPreviewView) | |
| contactPreviewView.translatesAutoresizingMaskIntoConstraints = false | |
| NSLayoutConstraint.activate([ // this line of code more performant than activating each constraint individually | |
| contactPreviewView.widthAnchor.constraint(equalToConstant: 150), | |
| contactPreviewView.heightAnchor.constraint(equalToConstant: 150), |
This file contains hidden or 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
| guard let path = Bundle.main.path(forResource: "ScheduleMock", ofType: "json") else { | |
| return | |
| } | |
| do { | |
| let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe) | |
| let schedule = try Mapper<TakeawayScheduleModel>().map(JSONString: data.string) | |
| print(schedule.title) | |
| } catch { | |
| print(error.localizedDescription) | |
| assertionFailure() |
This file contains hidden or 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
| print(String(data: try! JSONSerialization.data(withJSONObject: json, options: .prettyPrinted), encoding: .utf8 )!) |
This file contains hidden or 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
| @objc | |
| private func handleGet(_ sender: UIButton) { | |
| var superview = sender.superview | |
| while superview != nil { | |
| if let cell = superview as? UICollectionViewCell { | |
| guard let indexPath = collectionView.indexPath(for: cell), | |
| let objectIClickedOnto = diffableDataSource.itemIdentifier(for: indexPath) else { return } | |
| var snapshot = diffableDataSource.snapshot() | |
| snapshot.deleteItems([objectIClickedOnto]) | |
| diffableDataSource.apply(snapshot) |
This file contains hidden or 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
| // | |
| // UIView+Layout.swift | |
| // Project X | |
| // | |
| // Created by Brian Voong on 2/10/19. | |
| // Copyright © 2019 Brian Voong. All rights reserved. | |
| // | |
| import UIKit |
This file contains hidden or 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
| disabled_rules: | |
| excluded: | |
| - Pods | |
| - ProjectX/Supporting Files/R.generated.swift # R.swift | |
| opt_in_rules: | |
| - anyobject_protocol | |
| - array_init | |
| - attributes |
This file contains hidden or 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
| extension UIViewController { | |
| func hideKeyboardWhenTappedAround() { | |
| let tap = UITapGestureRecognizer( | |
| target: self, | |
| action: #selector(dismissKeyboard) | |
| ) | |
| tap.cancelsTouchesInView = false | |
| view.addGestureRecognizer(tap) | |
| } |
This file contains hidden or 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
| extension MyViewController: UITextFieldDelegate { | |
| func textFieldShouldReturn(_ textField: UITextField) -> Bool { | |
| // Try to find next responder | |
| if let nextTextField = textField.superview?.viewWithTag(textField.tag + 1) as? UITextField { | |
| nextTextField.becomeFirstResponder() | |
| } else { | |
| // Not found, so remove keyboard | |
| textField.resignFirstResponder() | |
| } | |
| // Do not add a line break |
This file contains hidden or 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
| import UIKit | |
| final class AppearanceManager { | |
| static let shared = AppearanceManager() | |
| private init () {} | |
| func setDefaultAppearance() { | |
| // Removes all navigation bar back button title | |
| UIBarButtonItem.appearance().setTitleTextAttributes( |
This file contains hidden or 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
| import Kingfisher | |
| import UIKit | |
| extension UIImageView { | |
| static func clearImageCache() { | |
| KingfisherManager.shared.cache.clearMemoryCache() | |
| KingfisherManager.shared.cache.clearDiskCache() | |
| } | |
| /// UIImageView+: Method for downloading image |
NewerOlder