Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢
Building stuff

Ignacio Romero Zurbuchen dzenbot

🐢
Building stuff
View GitHub Profile
View gist:c7db23174681a1aba857
NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1];
// Example: 1 UIKit 0x00540c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"];
NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString componentsSeparatedByCharactersInSet:separatorSet]];
[array removeObject:@""];
NSLog(@"Stack = %@", [array objectAtIndex:0]);
NSLog(@"Framework = %@", [array objectAtIndex:1]);
NSLog(@"Memory address = %@", [array objectAtIndex:2]);
NSLog(@"Class caller = %@", [array objectAtIndex:3]);
@dzenbot
dzenbot / gist:95d6e0805b8f0afd64a9
Created Jul 5, 2015
Gets the appropriate View Controller to present from and play nice with view hierarchy
View gist:95d6e0805b8f0afd64a9
- (UIViewController *)appropriatePresentationViewController
{
UIViewController *rootviewController = [UIApplication sharedApplication].keyWindow.rootViewController;
return rootviewController.presentedViewController ? : rootviewController;
}
@dzenbot
dzenbot / NSObject+SmartDescription.m
Last active Aug 29, 2015
Useful for printing custom property values on an NSObject subclass
View NSObject+SmartDescription.m
#import "NSObject+SmartDescription.h"
#import <objc/runtime.h>
@implementation NSObject (SmartDescription)
- (NSString *)smartDescription
{
NSMutableString *string = [NSMutableString stringWithFormat:@"<%@: %p> ", NSStringFromClass([self class]), self];
NSDictionary *properties = [self propertyList];
@dzenbot
dzenbot / -rangesInSubstring:
Last active Oct 29, 2019
NSString: Get all matching NSRange of a substring
View -rangesInSubstring:
- (NSArray *)rangesInSubstring:(NSString *)substring
{
NSError *error = NULL;
NSString *regex = [NSString stringWithFormat:@"\\b%@", substring];
NSRegularExpression *regExpression = [NSRegularExpression regularExpressionWithPattern:regex options:NSRegularExpressionCaseInsensitive error:&error];
NSMutableArray *ranges = [NSMutableArray array];
NSArray *matches = [regExpression matchesInString:self options:NSRegularExpressionSearch range:NSMakeRange(0, self.length)];
View gist:f4f6becb73702d5395d1
NSArray *sorted = [[dict allValues] sortedArrayUsingComparator:^NSComparisonResult(UIColor* obj1, UIColor* obj2) {
float hue, saturation, brightness, alpha;
[obj1 getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
float hue2, saturation2, brightness2, alpha2;
[obj2 getHue:&hue2 saturation:&saturation2 brightness:&brightness2 alpha:&alpha2];
if (hue < hue2)
return NSOrderedAscending;
else if (hue > hue2)
return NSOrderedDescending;
View FBAnimationPerformanceTracker.h
/*
* This is an example provided by Facebook are for non-commercial testing and
* evaluation purposes only.
*
* Facebook reserves all rights not expressly granted.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
@dzenbot
dzenbot / UIViewController+Detection
Last active Apr 24, 2018
An easy way to detect the topmost presented view controller on iOS
View UIViewController+Detection
+ (UIViewController *)topPresentedViewController
{
UIAppDelegate *delegate = [UIApplication sharedApplication].delegate;
UIViewController *visibleViewController = delegate.keyWindow.rootViewController;
while (visibleViewController.presentedViewController) {
visibleViewController = visibleViewController.presentedViewController;
}
@dzenbot
dzenbot / WatchSimulator-CoreText-Patch.sh
Last active Nov 20, 2016
CoreText header files are missing for the watchOS Simulator. This little script copies them from watchOS SDK easily.
View WatchSimulator-CoreText-Patch.sh
#!/bin/sh
# CoreText.framework is missing for the watchOS Simulator (but is available on the device platform SDK)
# https://openradar.appspot.com/27844864
#
# This script is a quick patch to solve this issue, so we are all capable of running CoreText APIs on the Watch simulator too,
# by copying the WatchOS SDK's CoreText header files into the WatchSimulator's. This works great, although since editing the SDK files
# is protected, it needs to be run with sudo.
# Returns the appropriate platform path containing the framework headers
View gist:619c4c4d342f11a04acce030ca292cb8
{
1.6.11: "https://kit-downloads.fabric.io/ios/io.fabric.sdk.ios/1.6.11/io.fabric.sdk.ios-default.zip"
}
You can’t perform that action at this time.