# Enable internal menu
defaults write com.apple.dt.Xcode ShowDVTDebugMenu -bool YES
# Enable project build time
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 Foundation | |
| import UIKit | |
| extension UIView { | |
| func addConstraintsWithFormat(_ format: String, views: UIView...) { | |
| var viewsDictionary = [String: UIView]() | |
| for (index, view) in views.enumerated() { | |
| let key = "v\(index)" |
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 | |
| @IBDesignable | |
| class CustomTextField: UITextField { | |
| @IBInspectable var isPasteEnabled: Bool = true | |
| @IBInspectable var isSelectEnabled: Bool = true | |
| @IBInspectable var isSelectAllEnabled: Bool = true |
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
| // Created by Vasily Ulianov on 09.02.17, updated in 2019. | |
| // License: MIT | |
| import Foundation | |
| /// Subclass of `Operation` that adds support of asynchronous operations. | |
| /// 1. Call `super.main()` when override `main` method. | |
| /// 2. When operation is finished or cancelled set `state = .finished` or `finish()` | |
| open class AsynchronousOperation: Operation { | |
| public override var isAsynchronous: Bool { |
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
| func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { | |
| if (cell.respondsToSelector(Selector("tintColor"))){ | |
| if (tableView == self.tvUserDetails) { | |
| let cornerRadius : CGFloat = 12.0 | |
| cell.backgroundColor = UIColor.clearColor() | |
| let layer: CAShapeLayer = CAShapeLayer() | |
| let pathRef:CGMutablePathRef = CGPathCreateMutable() | |
| let bounds: CGRect = CGRectInset(cell.bounds, 5, 0) | |
| var addLine: Bool = false | |
Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.
- Follow standard conventions.
- Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
- Boy scout rule. Leave the campground cleaner than you found it.
- Always find root cause. Always look for the root cause of a problem.
You can do it like this:
In your main view controller:
func showModal() {
let modalViewController = ModalViewController()
modalViewController.modalPresentationStyle = .OverCurrentContext
presentViewController(modalViewController, animated: true, completion: nil)
}
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
| /** Throttle wraps a block with throttling logic, guarantueeing that the block will never be called (by enquueing | |
| asynchronously on `queue`) more than once each `interval` seconds. If the wrapper callback is called more than once | |
| in an interval, it will use the most recent call's parameters when eventually calling the wrapped block (after `interval` | |
| has elapsed since the last call to the wrapped function) - i.e. calls are not queued and may get 'lost' by being superseded | |
| by a newer call. */ | |
| public func throttle<P>(interval: TimeInterval, queue: DispatchQueue, _ block: ((P) -> ())) -> ((P) -> ()) { | |
| var lastExecutionTime: TimeInterval? = nil | |
| var scheduledExecutionParameters: P? = nil | |
| let mutex = Mutex() |
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
| These values are returned as the error code property of an NSError object with the domain “NSURLErrorDomain”. | |
| Declaration | |
| SWIFT | |
| var NSURLErrorUnknown: Int { get } | |
| var NSURLErrorCancelled: Int { get } | |
| var NSURLErrorBadURL: Int { get } | |
| var NSURLErrorTimedOut: Int { get } | |
| var NSURLErrorUnsupportedURL: Int { get } | |
| var NSURLErrorCannotFindHost: Int { get } |