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 RxSwift | |
| // -- View Model | |
| struct LoginViewModel { | |
| var username = Variable<String>("") | |
| var password = Variable<String>("") | |
| var isValid : Observable<Bool>{ | |
| return Observable.combineLatest( self.username, self.password) |
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
| class MyCustomView : UIView { | |
| var sink : AnyObserver<SomeComplexStructure> { | |
| return AnyObserver { [weak self] event in | |
| switch event { | |
| case .next(let data): | |
| self?.something.text = data.property.text | |
| break | |
| case .error(let error): | |
| self?.backgroundColor = .red |
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 | |
| // Usage Examples | |
| let shadowColor = Color.shadow.value | |
| let shadowColorWithAlpha = Color.shadow.withAlpha(0.5) | |
| let customColorWithAlpha = Color.custom(hexString: "#123edd", alpha: 0.25).value | |
| enum Color { | |
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
| /usr/libexec/PlistBuddy -c 'Add :LSUIElement bool true' /Applications/iTerm.app/Contents/Info.plist |
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
| // Add the following to the Info.plist | |
| // <key>NSCameraUsageDescription</key> | |
| // <string>Allow our app to take photos</string> | |
| AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: {[weak self] status in | |
| if status { | |
| let session = AVCaptureSession() | |
| for device in AVCaptureDevice.devices() { | |
| if let device = device as? AVCaptureDevice, device.position == AVCaptureDevicePosition.back { | |
| self.device = device |
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 SDPresentationManager: NSObject, UIViewControllerTransitioningDelegate { | |
| func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? { | |
| return SDModalPresentationController(presentedViewController: presented, presenting: source) | |
| } | |
| func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { | |
| return SDModalTransitionPresentationAnimator() |
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 showPushNotification(title: String, details: String) { | |
| if #available(iOS 10.0, *) { | |
| let interval = TimeInterval(1) | |
| let trigger = UNTimeIntervalNotificationTrigger(timeInterval: interval, repeats: false) | |
| let content = UNMutableNotificationContent() | |
| content.title = title | |
| content.body = details | |
| let req = UNNotificationRequest(identifier: "localPushNotification", content: content, trigger: trigger) | |
| let center = UNUserNotificationCenter.current() | |
| center.getNotificationSettings(completionHandler: { settings in |
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 | |
| import MapKit | |
| extension MKMapView { | |
| func showLocation(at coordinate: CLLocationCoordinate2D) { | |
| self.removeOverlays(self.overlays) | |
| self.removeAnnotations(self.annotations) | |
| let annotation = MKPointAnnotation() |
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
| //: # Swift 3: JSON-serializable structs using protocols | |
| //: Most of the implementation is based on the code in [this blog post](http://codelle.com/blog/2016/5/an-easy-way-to-convert-swift-structs-to-json/) | |
| import Foundation | |
| //: ### Defining the protocols | |
| protocol JSONRepresentable { | |
| var JSONRepresentation: Any { get } | |
| } | |
| protocol JSONSerializable: JSONRepresentable {} |
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
| //: # Swift 3: URLSessionDelegate | |
| //: The following example shows how to use `OperationQueue` to queue the network requests. This is useful in many ways (for delaying queued requests when the networking goes down for example) | |
| import Foundation | |
| import PlaygroundSupport | |
| class Requester:NSObject { | |
| let opQueue = OperationQueue() | |
| var response:URLResponse? |