Skip to content

Instantly share code, notes, and snippets.

View grigorevp's full-sized avatar

Petr Grigorev grigorevp

  • Saint-Petersburg
View GitHub Profile
@cprovatas
cprovatas / Data+PrettyPrint.swift
Created May 23, 2018 15:52
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@WorldDownTown
WorldDownTown / ExtensionCompatibleSample.swift
Last active March 5, 2022 03:10
An example of Extension based on RxSwift in Swift.
public struct Extension<Base> {
public let base: Base
public init(_ base: Base) {
self.base = base
}
}
public protocol ExtensionCompatible {
associatedtype Compatible
var ex: Extension<Compatible> { get set }