Examples for how to create your own info panel, warning box and other decent looking notification in GitHub markdown.
All the boxes are single/two cell tables or two row tables.
❗ You have to read about this |
---|
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 | |
} |
class DiskStatus { | |
// MARK: Get String Value | |
class var totalDiskSpace: String { | |
get { | |
return ByteCountFormatter.string(fromByteCount: totalDiskSpaceInBytes, countStyle: ByteCountFormatter.CountStyle.file) | |
} | |
} | |
class var freeDiskSpace: String { |
/// If an error occurs while getting the amount of memory used, the first returned value in the tuple will be 0. | |
func getMemoryUsedAndDeviceTotalInMegabytes() -> (Float, Float) { | |
// https://stackoverflow.com/questions/5887248/ios-app-maximum-memory-budget/19692719#19692719 | |
// https://stackoverflow.com/questions/27556807/swift-pointer-problems-with-mach-task-basic-info/27559770#27559770 | |
var used_megabytes: Float = 0 | |
let total_bytes = Float(ProcessInfo.processInfo.physicalMemory) |
// | |
// ExtensionURLRequest.swift | |
// | |
// Created by Abhishek Maurya on 16/07/20. | |
// Copyright © 2020. All rights reserved. | |
// | |
import Foundation | |
extension URLRequest { |
class ViewController: UIViewController { | |
private(set) var tap: UITapGestureRecognizer | |
init(tap: UITapGestureRecognizer) { | |
self.tap = tap | |
super.init(nibName: nil, bundle: nil) | |
} | |
required init?(coder: NSCoder) { |
class MyObject: NSObject { | |
@objc dynamic func getName(_ name: String) -> String { | |
return name | |
} | |
} | |
class FakeMyObject: NSObject { | |
@objc dynamic func getName(_ name: String) -> String { | |
return name + " concat" | |
} |
import Foundation | |
protocol AsyncDispatcher { | |
func async( | |
group: DispatchGroup?, | |
qos: DispatchQoS, | |
flags: DispatchWorkItemFlags, | |
execute work: @escaping @convention(block) () -> Void | |
) | |
func async(execute work: @escaping @convention(block) () -> Void) |
func getDocumentsDirectory() -> URL { | |
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) | |
return paths[0] | |
} | |
func writeOnFile(str: String) { | |
let filename = getDocumentsDirectory().appendingPathComponent("output.txt") | |
do { | |
if FileManager.default.fileExists(atPath: filename.path), let data = "\(str)\n".data(using: .utf8) { |
import Foundation | |
/* | |
"Method swizzling is the process of changing the implementation of an existing selector. | |
It’s a technique made possible by the fact that method invocations in Objective-C can be | |
changed at runtime, by changing how selectors are mapped to underlying functions in a | |
class’s dispatch table." | |
Source: https://nshipster.com/method-swizzling/ | |
"This is only possible because in Objective-C the method to call when a message is sent |