Author: Chris Lattner
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
// Author: SwiftUI-Lab (swiftui-lab.com) | |
// Description: Implementation of the showSizes() debugging modifier | |
// blog article: https://swiftui-lab.com/layout-protocol-part-2 | |
import SwiftUI | |
struct MeasureExample: View { | |
var body: some View { | |
VStack { |
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
sealed class Optional<out T: Any> { | |
abstract val isPresent: Boolean | |
} | |
object None : Optional<Nothing>() { | |
override val isPresent: Boolean = false | |
} | |
data class Some<T: Any>(val value: T) : Optional<T>() { | |
override val isPresent: Boolean = true | |
} | |
fun <T: Any> T?.asOptional(): Optional<T> = this?.let(::Some) ?: None |
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
// | |
// TSAN_OPTIONS.h | |
// PSPDFKit | |
// | |
// Copyright © 2016 PSPDFKit GmbH. All rights reserved. | |
// Example code licensed under MIT. Enjoy! | |
// | |
#if __has_feature(thread_sanitizer) |
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 rx.Observable; | |
import rx.subjects.PublishSubject; | |
import rx.subjects.SerializedSubject; | |
import rx.subjects.Subject; | |
/** | |
* @author <a href="mailto:[email protected]">Jared Burrows</a> | |
*/ | |
public final class RxBus { | |
private final Subject<Object, Object> bus = new SerializedSubject<>(PublishSubject.create()); |
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 XCPlayground | |
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true | |
let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 667.0)) | |
containerView.backgroundColor = UIColor.whiteColor() | |
XCPlaygroundPage.currentPage.liveView = containerView | |
var aboutTextView = UITextView(frame: CGRect(x: 12.0, y: 20.0, width: containerView.frame.size.width - 12.0, height: 200.0)) | |
aboutTextView.textAlignment = .Left |
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 getProductIdFromReceipt(_ data:Data) -> String? //Swift 2: func getProductIdFromReceipt(data:NSData) -> String? | |
{ | |
//Swift 2: var p = UnsafePointer<UInt8>(data.bytes) | |
//Swift 3 | |
var p : UnsafePointer? = (data as NSData).bytes.bindMemory(to: UInt8.self, capacity: data.count) | |
let dataLength = data.length | |
var type:Int32 = 0 | |
var tag:Int32 = 0 |
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 | |
//let octets = pkcs7_d_data(pkcs7_d_sign(receiptPKCS7).memory.contents) | |
//var ptr = UnsafePointer<UInt8>(octets.memory.data) | |
//let end = ptr.advancedBy(Int(octets.memory.length)) | |
//Swift 3 | |
let octets = pkcs7_d_data(pkcs7_d_sign(receiptPKCS7).pointee.contents) | |
var ptr = UnsafePointer<UInt8>(octets?.pointee.data) | |
let end = ptr?.advanced(by: Int((octets?.pointee.length)!)) |
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
extension String { | |
func size(withAttributes attrs: [String:AnyObject], constrainedTo box: NSSize) -> NSRect { | |
let storage = NSTextStorage(string: self) | |
let container = NSTextContainer(containerSize: NSSize(width: box.width, height: box.height)) | |
let layout = NSLayoutManager() | |
layout.addTextContainer(container) | |
storage.addLayoutManager(layout) | |
storage.addAttributes(attrs, range: NSMakeRange(0, storage.length)) | |
container.lineFragmentPadding = 0.0 | |
let _ = layout.glyphRangeForTextContainer(container) |
NewerOlder