Skip to content

Instantly share code, notes, and snippets.

View dzenbot's full-sized avatar

Ignacio Romero Zurbuchen dzenbot

  • DZN Technologies
  • Canada
View GitHub Profile
{
1.6.11: "https://kit-downloads.fabric.io/ios/io.fabric.sdk.ios/1.6.11/io.fabric.sdk.ios-default.zip"
}
@dzenbot
dzenbot / WatchSimulator-CoreText-Patch.sh
Last active November 20, 2016 20:42
CoreText header files are missing for the watchOS Simulator. This little script copies them from watchOS SDK easily.
#!/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
@dzenbot
dzenbot / UIViewController+Detection
Last active April 24, 2018 07:22
An easy way to detect the topmost presented view controller on iOS
+ (UIViewController *)topPresentedViewController
{
UIAppDelegate *delegate = [UIApplication sharedApplication].delegate;
UIViewController *visibleViewController = delegate.keyWindow.rootViewController;
while (visibleViewController.presentedViewController) {
visibleViewController = visibleViewController.presentedViewController;
}
/*
* 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 / gist:f4f6becb73702d5395d1
Created October 9, 2015 15:50
Sort UIColors in a human way (snippet from http://stackoverflow.com/a/8585285)
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;
@dzenbot
dzenbot / -rangesInSubstring:
Last active October 29, 2019 20:05
NSString: Get all matching NSRange of a substring
- (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)];
@dzenbot
dzenbot / NSObject+SmartDescription.m
Last active March 19, 2021 22:59
Useful for printing custom property values on an NSObject subclass
#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 / gist:95d6e0805b8f0afd64a9
Created July 5, 2015 13:14
Gets the appropriate View Controller to present from and play nice with view hierarchy
- (UIViewController *)appropriatePresentationViewController
{
UIViewController *rootviewController = [UIApplication sharedApplication].keyWindow.rootViewController;
return rootviewController.presentedViewController ? : rootviewController;
}
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]);