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 8000Each 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 8000| /// 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> { |
| 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)) | |
| } |
| 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. |
| /* | |
| 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 |
| 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 { | |
| 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")] |
var는 function-scoped이고, let, const는 block-scoped입니다.
function-scoped와 block-scoped가 무슨말이냐?
| // Change the app icon without showing the system alert | |
| // The trick is to call setAlternateIconName(_:completionHandler:), then | |
| // immediately show (then immediately hide) a temp ViewController. | |
| // This seems to interrupt the system dialog box, which never shows. | |
| if UIApplication.shared.supportsAlternateIcons { | |
| UIApplication.shared.setAlternateIconName("nameOfAlternateIcon") | |
| let tempViewController = UIViewController() | |
| class FairPlayer: AVPlayer { | |
| private let queue = DispatchQueue(label: "com.icapps.fairplay.queue") | |
| func play(asset: AVURLAsset) { | |
| // Set the resource loader delegate to this class. The `resourceLoader`'s delegate will be | |
| // triggered when FairPlay handling is required. | |
| asset.resourceLoader.setDelegate(self, queue: queue) | |
| // Load the asset in the player. |