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
var mySingleton = (function() { | |
var instance; | |
function init() { | |
// Private methods and variables | |
function privateMethod() { | |
console.log("I am private"); | |
} |
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 UIWindow { | |
func visibleViewController() -> UIViewController? { | |
if let rootViewController: UIViewController = self.rootViewController { | |
return UIWindow.getVisibleViewControllerFrom(vc: rootViewController) | |
} | |
return nil | |
} | |
class func getVisibleViewControllerFrom(vc:UIViewController) -> UIViewController { |
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
// Info.plist requires "Privacy - Photo Library Additions Usage Description" | |
UIImageWriteToSavedPhotosAlbum(image, nil, nil, 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
struct Device { | |
// iDevice detection code | |
static let IS_IPAD = UIDevice.current.userInterfaceIdiom == .pad | |
static let IS_IPHONE = UIDevice.current.userInterfaceIdiom == .phone | |
static let IS_RETINA = UIScreen.main.scale >= 2.0 | |
static let SCREEN_WIDTH = Int(UIScreen.main.bounds.size.width) | |
static let SCREEN_HEIGHT = Int(UIScreen.main.bounds.size.height) | |
static let SCREEN_MAX_LENGTH = Int( max(SCREEN_WIDTH, SCREEN_HEIGHT) ) | |
static let SCREEN_MIN_LENGTH = Int( min(SCREEN_WIDTH, SCREEN_HEIGHT) ) |
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
@IBDesignable | |
class EdgeInsetLabel: UILabel { | |
var textInsets = UIEdgeInsets.zero { | |
didSet { invalidateIntrinsicContentSize() } | |
} | |
override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect { | |
let insetRect = UIEdgeInsetsInsetRect(bounds, textInsets) | |
let textRect = super.textRect(forBounds: insetRect, limitedToNumberOfLines: numberOfLines) | |
let invertedInsets = UIEdgeInsets(top: -textInsets.top, |
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
fileprivate extension Selector { | |
static let buttonTapped = #selector(ViewController.buttonTapped) | |
static let deviceOrientationDidChange = #selector(ViewController.deviceOrientationDidChange) | |
} | |
// Example on how to use it | |
NotificationCenter.default.addObserver(self, selector: .deviceOrientationDidChange, | |
name: NSNotification.Name.UIDeviceOrientationDidChange, | |
object: 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
class ImagePicker: UIViewController, UINavigationControllerDelegate { | |
@IBOutlet var pictureView: UIImageView! | |
func tapAddPicture(_ sender: Any) { | |
let imagePickerController = UIImagePickerController() | |
imagePickerController.delegate = self | |
imagePickerController.mediaTypes = ["public.image", "public.movie"] | |
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) | |
actionSheet.addAction(UIAlertAction(title: "Take Photo", style: .default, handler: { (action:UIAlertAction) 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 Foundation | |
func readInput() { | |
let numberOfCases = Int(readLine() ?? "0")! | |
for _case in 0..<numberOfCases { | |
guard let currentLine = readLine() as String! else { | |
return | |
} | |
let lineValues = getIntegersOf(line: currentLine, separatedBy: " ") |
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
override func numberOfSectionsInTableView(in tableView: UITableView) -> Int { | |
return NUMBER_OF_SECTIONS | |
} | |
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return NUMBER_OF_ELEMENTS_PER_SECTION | |
} | |
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: "CELL_IDENTIFIER", for: indexPath) |
NewerOlder