Skip to content

Instantly share code, notes, and snippets.

View igrechuhin's full-sized avatar

Ilya Grechuhin igrechuhin

View GitHub Profile
@igrechuhin
igrechuhin / DebugPrinter.swift
Created October 6, 2021 14:41
DebugPrinter
final class DebugPrinter {
private var address2Name: [UnsafeMutableRawPointer: String] = [:]
private var typeIndex: [String: Int] = [:]
private let marker: String
private let formatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm:ss.SSS"
return formatter
}()
@igrechuhin
igrechuhin / libdispatch-efficiency-tips.md
Created March 6, 2020 13:29 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

I suspect most developers are using the libdispatch inefficiently due to the way it was presented to us at the time it was introduced and for many years after that, and due to the confusing documentation and API. I realized this after reading the 'concurrency' discussion on the swift-evolution mailing-list, in particular the messages from Pierre Habouzit (who is the libdispatch maintainer at Apple) are quite enlightening (and you can also find many tweets from him on the subject).

My take-aways are:

######################
# Options
######################
REVEAL_ARCHIVE_IN_FINDER=false
FRAMEWORK_NAME="${PROJECT_NAME}"
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
@igrechuhin
igrechuhin / getUIImageForRGBAData.swift
Created September 6, 2016 13:53 — forked from irskep/getUIImageForRGBAData.swift
Convert RGBA bytes to UIImage in Swift
func getUIImageForRGBAData(#width: UInt, #height: UInt, #data: NSData) -> UIImage? {
let pixelData = data.bytes
let bytesPerPixel:UInt = 4
let scanWidth = bytesPerPixel * width
let provider = CGDataProviderCreateWithData(nil, pixelData, height * scanWidth, nil)
let colorSpaceRef = CGColorSpaceCreateDeviceRGB()
var bitmapInfo:CGBitmapInfo = .ByteOrderDefault;
bitmapInfo |= CGBitmapInfo(CGImageAlphaInfo.Last.rawValue)
Swift:
extension UIWindow {
func visibleViewController() -> UIViewController? {
if let rootViewController: UIViewController = self.rootViewController {
return UIWindow.getVisibleViewControllerFrom(rootViewController)
}
return nil
}
Class currentClass = [NSClassFromString(@"ClassName") class];
while (currentClass) {
    // Iterate over all instance methods for this class
    unsigned int methodCount;
    Method *methodList = class_copyMethodList(currentClass, &methodCount);

    unsigned int i = 0;
    for (; i < methodCount; i++) {

NSLog(@"%@ - %@", [NSString stringWithCString:class_getName(currentClass) encoding:NSUTF8StringEncoding], [NSString stringWithCString:sel_getName(method_getName(methodList[i])) encoding:NSUTF8StringEncoding]);