Skip to content

Instantly share code, notes, and snippets.

View jon-1's full-sized avatar
🆗
OK

Jonathan Michael jon-1

🆗
OK
View GitHub Profile
@jon-1
jon-1 / Data+PrettyPrint.swift
Created July 27, 2020 20:54 — forked from cprovatas/Data+PrettyPrint.swift
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
}
import Foundation
import UIKit
let CHAR_LIMIT = 75
extension String {
func replace(string:String, replacement:String) -> String {
return self.stringByReplacingOccurrencesOfString(string, withString: replacement, options: NSStringCompareOptions.LiteralSearch, range: nil)
}
@jon-1
jon-1 / gist:16eabdc55ae2767b6f1231e94e8933fb
Created July 29, 2016 15:01
Round only top or bottom corners of a UIView
extension UIView {
enum Corners {
case Top
case Bottom
}
func roundCorners(radius : CGFloat, corners : Corners) {
let radius : CGFloat = radius
var maskFrame = self.bounds
maskFrame.size.height += radius