-
var는function-scoped이고,let,const는block-scoped입니다. -
function-scoped와block-scoped가 무슨말이냐?
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 Int { | |
| func formatUsingAbbrevation () -> String { | |
| let numFormatter = NSNumberFormatter() | |
| typealias Abbrevation = (threshold:Double, divisor:Double, suffix:String) | |
| let abbreviations:[Abbrevation] = [(0, 1, ""), | |
| (1000.0, 1000.0, "K"), | |
| (100_000.0, 1_000_000.0, "M"), | |
| (100_000_000.0, 1_000_000_000.0, "B")] |
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 | |
| extension UIImage { | |
| // colorize image with given tint color | |
| // this is similar to Photoshop's "Color" layer blend mode | |
| // this is perfect for non-greyscale source images, and images that have both highlights and shadows that should be preserved | |
| // white will stay white and black will stay black as the lightness of the image is preserved | |
| func tint(tintColor: UIColor) -> UIImage { | |
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
| /* | |
| Copyright (C) 2016 Apple Inc. All Rights Reserved. | |
| See LICENSE.txt for this sample’s licensing information | |
| Abstract: | |
| `DirectoryMonitor` is used to monitor the contents of the provided directory by using a GCD dispatch source. | |
| */ | |
| import Foundation |
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
| For a background download service with NSURLSession | |
| 1. Create a download task with background session configuration with NSURLSession delegates. | |
| 2. If, application is in foreground NSURLsession delegate will be called directly. | |
| 3. If application is background or killed additional methods are needed in the app delegate . | |
| 4. "handleEventsForBackgroundURLSession" will be called first, where it is necessary to reinstate the session object with the delegate again. Otherwise delegate methods will not be called. | |
| 5. "URLSessionDidFinishEventsForBackgroundURLSession" will be called once everything is done. You can decide what you want to do once the download is complete like updating the UI. |
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 countLabelLines(label: UILabel) -> Int { | |
| // Call self.layoutIfNeeded() if your view uses auto layout | |
| let myText = label.text! as NSString | |
| let rect = CGSize(width: label.bounds.width, height: CGFloat.greatestFiniteMagnitude) | |
| let labelSize = myText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: label.font], context: nil) | |
| return Int(ceil(CGFloat(labelSize.height) / label.font.lineHeight)) | |
| } |
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
| /// An object that has some tear-down logic | |
| public protocol Disposable { | |
| func dispose() | |
| } | |
| /// An event provides a mechanism for raising notifications, together with some | |
| /// associated data. Multiple function handlers can be added, with each being invoked, | |
| /// with the event data, when the event is raised. | |
| public class Event<T> { |
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000NewerOlder