This file contains 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 open(_ filePath: String) throws -> NSArray { | |
let data = try Data(contentsOf: URL(fileURLWithPath: filePath)) | |
let object: Any? | |
if #available(OSX 10.11, *) { | |
object = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data as NSData) | |
} else { | |
let unarchiver = NSKeyedUnarchiver(forReadingWith: data) | |
object = unarchiver.decodeObject(forKey: "root") | |
} | |
guard let unarchivedObject = object else { |
This file contains 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
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
UIImage *image = [UIImage imageNamed:@"test.png"]; | |
self.imageView.image = [self blackAndWhiteFromImage:image]; | |
} | |
- (UIImage * _Nullable)makeBlackPixelsRedInImage:(UIImage *)image { | |
UInt32 black = [self pixelFromRed:0 green:0 blue:0 alpha:255]; | |
UInt32 red = [self pixelFromRed:255 green:0 blue:0 alpha:255]; |
This file contains 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
// I'd define a Swift struct that captures all of the needed `Complex` arithmetic: | |
/// Complex number | |
struct Complex { | |
let real: Double | |
let imaginary: Double | |
init(real: Double, imaginary: Double) { | |
self.real = real |
This file contains 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 os.log | |
// This reported: | |
// | |
// 2016-10-19 21:27:58.383124 MyApp[6452:1422313] about to set to `nil` | |
// 2016-10-19 21:27:58.383439 MyApp[6452:1422313] set to nil | |
// 2016-10-19 21:27:58.383711 MyApp[6452:1422313] finished setting to `nil` | |
class ViewController: UIViewController { |
This file contains 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 2 | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
perform1 { | |
self.perform2 { | |
self.perform3 { | |
print("everything done") | |
} |
This file contains 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 | |
class ChildViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
print("ChildViewController.viewDidLoad") | |
} |
This file contains 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
// Don't declare this `static`, as you never want to be tempted (or accidentally) refer to this static directly: | |
// | |
// static AFHTTPSessionManager *requestManager ; | |
@implementation Mysevers // this was the name you used | |
// always use this singleton | |
+ (AFHTTPSessionManager *)sharedHTTPSession { | |
static dispatch_once_t onceToken; |
This file contains 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
/// Export MPMediaItem to temporary file. | |
/// | |
/// - Parameters: | |
/// - assetURL: The `assetURL` of the `MPMediaItem`. | |
/// - completionHandler: Closure to be called when the export is done. The parameters are a boolean `success`, the `URL` of the temporary file, and an optional `Error` if there was any problem. The parameters of the closure are: | |
/// | |
/// - fileURL: The `URL` of the temporary file created for the exported results. | |
/// - error: The `Error`, if any, of the asynchronous export process. | |
func export(_ assetURL: URL, completionHandler: @escaping (_ fileURL: URL?, _ error: Error?) -> ()) { |
This file contains 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 Cocoa | |
@IBDesignable | |
class HolyView: NSView { | |
override func draw(_ dirtyRect: NSRect) { | |
super.draw(dirtyRect) | |
let center1 = NSPoint(x: bounds.size.width * 0.3 + bounds.origin.x, y: bounds.size.height / 2 + bounds.origin.y) | |
let radius1 = bounds.size.width / 6 |
This file contains 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
// GradientView.swift | |
// | |
// Created by Robert Ryan on 12/29/16. | |
// Copyright © 2016 Robert Ryan. All rights reserved. | |
// | |
import Cocoa | |
@IBDesignable | |
public class GradientView: NSView { |