Skip to content

Commit

Permalink
update license, add how to
Browse files Browse the repository at this point in the history
  • Loading branch information
steipete committed Jul 29, 2012
1 parent e1c1e0f commit 0a765f2
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
95 changes: 95 additions & 0 deletions HowTo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
HowTo -- Helpful Stuff
======================

My main resource for reverse engineering UICollection is [https://github.com/steipete/iOS6-Runtime-Headers](https://github.com/steipete/iOS6-Runtime-Headers).

// For debugging purposes only
``` objective-c
#ifdef DEBUG
NSString *_PSPDFPrintIvars(id obj, NSMutableSet *recursiveSet);
void PSPDFPrintIvars(id obj, BOOL printRecursive) {
NSString *ivarString = _PSPDFPrintIvars(obj, printRecursive ? [NSMutableSet set] : nil);
NSLog(@"%@", ivarString);
}

NSMutableDictionary *_PSDPFConvertIvarsToDictionary(Class class, id obj);
NSMutableDictionary *_PSDPFConvertIvarsToDictionary(Class class, id obj) {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
unsigned int ivarCount;
Ivar *ivars = class_copyIvarList(class, &ivarCount);
for (int i = 0; i < ivarCount; i++) {
NSString *name = @(ivar_getName(ivars[i]));
id value;
@try { value = [obj valueForKey:name]; }
@catch (NSException *exception) {
value = [exception reason];
}
value = value ?: [NSNull null];
[dict setObject:value forKey:name];
}
free(ivars);
return dict;
}

NSString *_PSPDFPrintIvars(id obj, NSMutableSet *recursiveSet) {
NSMutableString *string = [NSMutableString string];
[recursiveSet addObject:obj];

// query ivar list
NSMutableSet *ivarDictionaries = [NSMutableSet set];
NSMutableDictionary *dict = _PSDPFConvertIvarsToDictionary([obj class], obj);
Class superClass = class_getSuperclass([obj class]);
while(superClass && ![superClass isEqual:[NSObject class]]) {
NSDictionary *superClassIvarDict = _PSDPFConvertIvarsToDictionary(superClass, obj);
if ([superClassIvarDict count]) {
dict[NSStringFromClass(superClass)] = superClassIvarDict;

if ([NSStringFromClass(superClass) hasPrefix:@"UICollection"] || [NSStringFromClass(superClass) hasPrefix:@"_UI"]) {
[ivarDictionaries addObject:superClassIvarDict];
}
}
superClass = class_getSuperclass(superClass);
}
if ([dict count]) {
[string appendFormat:@"<%@= %@>", NSStringFromClass([obj class]), [dict description]];
}
// dig deeper if recursive is enabled
if (recursiveSet) {
[dict enumerateKeysAndObjectsUsingBlock:^(id key, id dictObj, BOOL *stop) {
if ([ivarDictionaries containsObject:dictObj]) {
[dictObj enumerateKeysAndObjectsUsingBlock:^(id key, id dictObj, BOOL *stop) {

if (![recursiveSet containsObject:dictObj] && (![dictObj isKindOfClass:[NSDictionary class]] || [dictObj count] > 0) && ![dictObj isKindOfClass:[NSSet set]] && ![dictObj isKindOfClass:NSClassFromString(@"NSConcreteValue")]) {
if ([[dictObj class] conformsToProtocol:@protocol(NSFastEnumeration)]) {
for (id anObj in dictObj) {
[string appendString:_PSPDFPrintIvars(anObj, recursiveSet)];
}
}else {
[string appendString:_PSPDFPrintIvars(dictObj, recursiveSet)];
}
}
}];
}else {
if (![recursiveSet containsObject:dictObj] && (![dictObj isKindOfClass:[NSDictionary class]] || [dictObj count] > 0) && ![dictObj isKindOfClass:[NSSet set]] && ![dictObj isKindOfClass:NSClassFromString(@"NSConcreteValue")]) {
if ([[dictObj class] conformsToProtocol:@protocol(NSFastEnumeration)]) {
for (id anObj in dictObj) {
[string appendString:_PSPDFPrintIvars(anObj, recursiveSet)];
}
}else {
[string appendString:_PSPDFPrintIvars(dictObj, recursiveSet)];
}
}
}
}];
}

// custom stuff (e.g. get a id * variable that's not KVO compliant)
if([NSStringFromClass([obj class]) isEqualToString:@"UICollectionViewData"]) {
id *outvalue;
object_getInstanceVariable(obj, "_globalItems", (void **)&outvalue);
NSLog(@"done");
}
return string;
}
#endif
```
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2012 Peter Steinberger <steipete@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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 NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ Another goal (at least super useful for debugging) is interoperability between U

(*) Note that for some methods we can't use the _ underscore variants or we risk to get a false-positive on private API use. I've added some runtime hacks to dynamcially add block forwarders for those cases (mainly for UI/PS interoperability)

License will be MIT.
### Creator

[Peter Steinberger](http://github.com/steipete), [@steipete](https://twitter.com/steipete)

and hopefully lots of others! See [HowTo](HowTo.m) for helpful details.

## License

PSCollectionView is available under the MIT license. See the LICENSE file for more info.

0 comments on commit 0a765f2

Please sign in to comment.