Skip to content

Instantly share code, notes, and snippets.

@danhd123
danhd123 / framework_deps.bash
Last active September 13, 2019 08:10
iOS/macOS Framework dependencies
#!/bin/bash
# Generate a list of all* the frameworks' dependencies. Output to file to not blow out your scrollback
# * for an approximate definition of "all". There are a few it doesn't catch in PrivateFrameworks
cd /System/Library/Frameworks # or PrivateFrameworks, or /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks
for file in `ls`
do
fwkname=$(echo "$file" | cut -f 1 -d '.')
otool -L $file/$fwkname
@danhd123
danhd123 / gist:c1dc8242f48ace176cf8
Last active August 29, 2015 14:24
How to make Strings work in a Uint8 raw value enum.
extension UInt8 : StringLiteralConvertible {
typealias ExtendedGraphemeClusterLiteralType = String
typealias UnicodeScalarLiteralType = String
public init(stringLiteral value: StringLiteralType){
self.init(([UInt8]() + value.utf8)[0])
}
public init(extendedGraphemeClusterLiteral value: String){
self.init(([UInt8]() + value.utf8)[0])
@danhd123
danhd123 / gist:374ef684fa460eec943e
Last active August 29, 2015 14:21
A horrible thing to do with KVO.
- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context
{
BOOL isKVOBefore = NO;
Class realClass = object_getClass(self);
if (realClass != [self class]) //For more safety, parse the name, looking for the string "Autonotifying"
{
isKVOBefore = YES;
}
if (!isKVONow)
+ (id)objectForKeyedSubscript:(id)key
{
unsigned int outCount;
if ([self instancesRespondToSelector:@selector(initWithCoder:)] && [key isKindOfClass:[NSCoder class]])
{
return [[self alloc] initWithCoder:key];
}
//todo: cache these results in an associated object
Method *theseMethods = class_copyMethodList(self, &outCount);
NSMutableIndexSet *methodArrayHits = [[NSMutableIndexSet alloc] init];