Skip to content

Instantly share code, notes, and snippets.

View malcommac's full-sized avatar
👋
Nice to meet u

Daniele Margutti malcommac

👋
Nice to meet u
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
}
@andr3a88
andr3a88 / .swiftlint.yml
Last active March 9, 2020 10:41
SwiftLint file
disabled_rules: # rule identifiers to exclude from running
- force_cast
- legacy_constant
- legacy_constructor
- nesting
- trailing_whitespace
- type_name
- identifier_name
- cyclomatic_complexity
- explicit_self
import Foundation
final class SafeSyncQueue {
struct QueueIdentity {
let label: String
}
let queue: DispatchQueue
@duemunk
duemunk / AsynchronousThrow.swift
Last active February 15, 2017 02:28
An example of how you can use the error handling in Swift 2.0 for an asynchronous API.
typealias EmptyResult = () throws -> ()
typealias AsyncResult = (EmptyResult) -> ()
typealias JsonResult = () throws -> JSON
typealias AsyncJsonResult = (JsonResult) -> ()
class GetResponse {
func main() {