added files via upload

This commit is contained in:
Balackburn
2023-06-27 09:54:41 +02:00
commit 2ff6aac218
1420 changed files with 88898 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
//
// Cocoa+FLEXShortcuts.h
// Pods
//
// Created by Tanner on 2/24/21.
//
//
#import <UIKit/UIKit.h>
@interface UIAlertAction (FLEXShortcuts)
@property (nonatomic, readonly) NSString *flex_styleName;
@end

View File

@@ -0,0 +1,25 @@
//
// Cocoa+FLEXShortcuts.m
// Pods
//
// Created by Tanner on 2/24/21.
//
//
#import "Cocoa+FLEXShortcuts.h"
@implementation UIAlertAction (FLEXShortcuts)
- (NSString *)flex_styleName {
switch (self.style) {
case UIAlertActionStyleDefault:
return @"Default style";
case UIAlertActionStyleCancel:
return @"Cancel style";
case UIAlertActionStyleDestructive:
return @"Destructive style";
default:
return [NSString stringWithFormat:@"Unknown (%@)", @(self.style)];
}
}
@end

View File

@@ -0,0 +1,21 @@
//
// NSDictionary+ObjcRuntime.h
// FLEX
//
// Derived from MirrorKit.
// Created by Tanner on 7/5/15.
// Copyright (c) 2020 FLEX Team. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface NSDictionary (ObjcRuntime)
/// \c kFLEXPropertyAttributeKeyTypeEncoding is the only required key.
/// Keys representing a boolean value should have a value of \c YES instead of an empty string.
- (NSString *)propertyAttributesString;
+ (instancetype)attributesDictionaryForProperty:(objc_property_t)property;
@end

View File

@@ -0,0 +1,107 @@
//
// NSDictionary+ObjcRuntime.m
// FLEX
//
// Derived from MirrorKit.
// Created by Tanner on 7/5/15.
// Copyright (c) 2020 FLEX Team. All rights reserved.
//
#import "NSDictionary+ObjcRuntime.h"
#import "FLEXRuntimeUtility.h"
@implementation NSDictionary (ObjcRuntime)
/// See this link on how to construct a proper attributes string:
/// https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html
- (NSString *)propertyAttributesString {
if (!self[kFLEXPropertyAttributeKeyTypeEncoding]) return nil;
NSMutableString *attributes = [NSMutableString new];
[attributes appendFormat:@"T%@,", self[kFLEXPropertyAttributeKeyTypeEncoding]];
for (NSString *attribute in self.allKeys) {
FLEXPropertyAttribute c = (FLEXPropertyAttribute)[attribute characterAtIndex:0];
switch (c) {
case FLEXPropertyAttributeTypeEncoding:
break;
case FLEXPropertyAttributeBackingIvarName:
[attributes appendFormat:@"%@%@,",
kFLEXPropertyAttributeKeyBackingIvarName,
self[kFLEXPropertyAttributeKeyBackingIvarName]
];
break;
case FLEXPropertyAttributeCopy:
if ([self[kFLEXPropertyAttributeKeyCopy] boolValue])
[attributes appendFormat:@"%@,", kFLEXPropertyAttributeKeyCopy];
break;
case FLEXPropertyAttributeCustomGetter:
[attributes appendFormat:@"%@%@,",
kFLEXPropertyAttributeKeyCustomGetter,
self[kFLEXPropertyAttributeKeyCustomGetter]
];
break;
case FLEXPropertyAttributeCustomSetter:
[attributes appendFormat:@"%@%@,",
kFLEXPropertyAttributeKeyCustomSetter,
self[kFLEXPropertyAttributeKeyCustomSetter]
];
break;
case FLEXPropertyAttributeDynamic:
if ([self[kFLEXPropertyAttributeKeyDynamic] boolValue])
[attributes appendFormat:@"%@,", kFLEXPropertyAttributeKeyDynamic];
break;
case FLEXPropertyAttributeGarbageCollectible:
[attributes appendFormat:@"%@,", kFLEXPropertyAttributeKeyGarbageCollectable];
break;
case FLEXPropertyAttributeNonAtomic:
if ([self[kFLEXPropertyAttributeKeyNonAtomic] boolValue])
[attributes appendFormat:@"%@,", kFLEXPropertyAttributeKeyNonAtomic];
break;
case FLEXPropertyAttributeOldTypeEncoding:
[attributes appendFormat:@"%@%@,",
kFLEXPropertyAttributeKeyOldStyleTypeEncoding,
self[kFLEXPropertyAttributeKeyOldStyleTypeEncoding]
];
break;
case FLEXPropertyAttributeReadOnly:
if ([self[kFLEXPropertyAttributeKeyReadOnly] boolValue])
[attributes appendFormat:@"%@,", kFLEXPropertyAttributeKeyReadOnly];
break;
case FLEXPropertyAttributeRetain:
if ([self[kFLEXPropertyAttributeKeyRetain] boolValue])
[attributes appendFormat:@"%@,", kFLEXPropertyAttributeKeyRetain];
break;
case FLEXPropertyAttributeWeak:
if ([self[kFLEXPropertyAttributeKeyWeak] boolValue])
[attributes appendFormat:@"%@,", kFLEXPropertyAttributeKeyWeak];
break;
default:
return nil;
break;
}
}
[attributes deleteCharactersInRange:NSMakeRange(attributes.length-1, 1)];
return attributes.copy;
}
+ (instancetype)attributesDictionaryForProperty:(objc_property_t)property {
NSMutableDictionary *attrs = [NSMutableDictionary new];
for (NSString *key in FLEXRuntimeUtility.allPropertyAttributeKeys) {
char *value = property_copyAttributeValue(property, key.UTF8String);
if (value) {
attrs[key] = [[NSString alloc]
initWithBytesNoCopy:value
length:strlen(value)
encoding:NSUTF8StringEncoding
freeWhenDone:YES
];
}
}
return attrs.copy;
}
@end

View File

@@ -0,0 +1,20 @@
//
// NSMapTable+FLEX_Subscripting.h
// FLEX
//
// Created by Tanner Bennett on 1/9/20.
// Copyright © 2020 FLEX Team. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSMapTable<KeyType, ObjectType> (FLEX_Subscripting)
- (nullable ObjectType)objectForKeyedSubscript:(KeyType)key;
- (void)setObject:(nullable ObjectType)obj forKeyedSubscript:(KeyType <NSCopying>)key;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,21 @@
//
// NSMapTable+FLEX_Subscripting.m
// FLEX
//
// Created by Tanner Bennett on 1/9/20.
// Copyright © 2020 FLEX Team. All rights reserved.
//
#import "NSMapTable+FLEX_Subscripting.h"
@implementation NSMapTable (FLEX_Subscripting)
- (id)objectForKeyedSubscript:(id)key {
return [self objectForKey:key];
}
- (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key {
[self setObject:obj forKey:key];
}
@end

View File

@@ -0,0 +1,33 @@
//
// NSString+FLEX.h
// FLEX
//
// Created by Tanner on 3/26/17.
// Copyright © 2017 Tanner Bennett. All rights reserved.
//
#import "FLEXRuntimeConstants.h"
@interface NSString (FLEXTypeEncoding)
///@return whether this type starts with the const specifier
@property (nonatomic, readonly) BOOL flex_typeIsConst;
/// @return the first char in the type encoding that is not the const specifier
@property (nonatomic, readonly) FLEXTypeEncoding flex_firstNonConstType;
/// @return the first char in the type encoding after the pointer specifier, if it is a pointer
@property (nonatomic, readonly) FLEXTypeEncoding flex_pointeeType;
/// @return whether this type is an objc object of any kind, even if it's const
@property (nonatomic, readonly) BOOL flex_typeIsObjectOrClass;
/// @return the class named in this type encoding if it is of the form \c @"MYClass"
@property (nonatomic, readonly) Class flex_typeClass;
/// Includes C strings and selectors as well as regular pointers
@property (nonatomic, readonly) BOOL flex_typeIsNonObjcPointer;
@end
@interface NSString (KeyPaths)
- (NSString *)flex_stringByRemovingLastKeyPathComponent;
- (NSString *)flex_stringByReplacingLastKeyPathComponent:(NSString *)replacement;
@end

View File

@@ -0,0 +1,160 @@
//
// NSString+FLEX.m
// FLEX
//
// Created by Tanner on 3/26/17.
// Copyright © 2017 Tanner Bennett. All rights reserved.
//
#import "NSString+FLEX.h"
@interface NSMutableString (Replacement)
- (void)replaceOccurencesOfString:(NSString *)string with:(NSString *)replacement;
- (void)removeLastKeyPathComponent;
@end
@implementation NSMutableString (Replacement)
- (void)replaceOccurencesOfString:(NSString *)string with:(NSString *)replacement {
[self replaceOccurrencesOfString:string withString:replacement options:0 range:NSMakeRange(0, self.length)];
}
- (void)removeLastKeyPathComponent {
if (![self containsString:@"."]) {
[self deleteCharactersInRange:NSMakeRange(0, self.length)];
return;
}
BOOL putEscapesBack = NO;
if ([self containsString:@"\\."]) {
[self replaceOccurencesOfString:@"\\." with:@"\\~"];
// Case like "UIKit\.framework"
if (![self containsString:@"."]) {
[self deleteCharactersInRange:NSMakeRange(0, self.length)];
return;
}
putEscapesBack = YES;
}
// Case like "Bund" or "Bundle.cla"
if (![self hasSuffix:@"."]) {
NSUInteger len = self.pathExtension.length;
[self deleteCharactersInRange:NSMakeRange(self.length-len, len)];
}
if (putEscapesBack) {
[self replaceOccurencesOfString:@"\\~" with:@"\\."];
}
}
@end
@implementation NSString (FLEXTypeEncoding)
- (NSCharacterSet *)flex_classNameAllowedCharactersSet {
static NSCharacterSet *classNameAllowedCharactersSet = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSMutableCharacterSet *temp = NSMutableCharacterSet.alphanumericCharacterSet;
[temp addCharactersInString:@"_"];
classNameAllowedCharactersSet = temp.copy;
});
return classNameAllowedCharactersSet;
}
- (BOOL)flex_typeIsConst {
if (!self.length) return NO;
return [self characterAtIndex:0] == FLEXTypeEncodingConst;
}
- (FLEXTypeEncoding)flex_firstNonConstType {
if (!self.length) return FLEXTypeEncodingNull;
return [self characterAtIndex:(self.flex_typeIsConst ? 1 : 0)];
}
- (FLEXTypeEncoding)flex_pointeeType {
if (!self.length) return FLEXTypeEncodingNull;
if (self.flex_firstNonConstType == FLEXTypeEncodingPointer) {
return [self characterAtIndex:(self.flex_typeIsConst ? 2 : 1)];
}
return FLEXTypeEncodingNull;
}
- (BOOL)flex_typeIsObjectOrClass {
FLEXTypeEncoding type = self.flex_firstNonConstType;
return type == FLEXTypeEncodingObjcObject || type == FLEXTypeEncodingObjcClass;
}
- (Class)flex_typeClass {
if (!self.flex_typeIsObjectOrClass) {
return nil;
}
NSScanner *scan = [NSScanner scannerWithString:self];
// Skip const
[scan scanString:@"r" intoString:nil];
// Scan leading @"
if (![scan scanString:@"@\"" intoString:nil]) {
return nil;
}
// Scan class name
NSString *name = nil;
if (![scan scanCharactersFromSet:self.flex_classNameAllowedCharactersSet intoString:&name]) {
return nil;
}
// Scan trailing quote
if (![scan scanString:@"\"" intoString:nil]) {
return nil;
}
// Return found class
return NSClassFromString(name);
}
- (BOOL)flex_typeIsNonObjcPointer {
FLEXTypeEncoding type = self.flex_firstNonConstType;
return type == FLEXTypeEncodingPointer ||
type == FLEXTypeEncodingCString ||
type == FLEXTypeEncodingSelector;
}
@end
@implementation NSString (KeyPaths)
- (NSString *)flex_stringByRemovingLastKeyPathComponent {
if (![self containsString:@"."]) {
return @"";
}
NSMutableString *mself = self.mutableCopy;
[mself removeLastKeyPathComponent];
return mself;
}
- (NSString *)flex_stringByReplacingLastKeyPathComponent:(NSString *)replacement {
// replacement should not have any escaped '.' in it,
// so we escape all '.'
if ([replacement containsString:@"."]) {
replacement = [replacement stringByReplacingOccurrencesOfString:@"." withString:@"\\."];
}
// Case like "Foo"
if (![self containsString:@"."]) {
return [replacement stringByAppendingString:@"."];
}
NSMutableString *mself = self.mutableCopy;
[mself removeLastKeyPathComponent];
[mself appendString:replacement];
[mself appendString:@"."];
return mself;
}
@end

View File

@@ -0,0 +1,23 @@
//
// NSString+ObjcRuntime.h
// FLEX
//
// Derived from MirrorKit.
// Created by Tanner on 7/1/15.
// Copyright (c) 2020 FLEX Team. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSString (Utilities)
/// A dictionary of property attributes if the receiver is a valid property attributes string.
/// Values are either a string or \c YES. Boolean attributes which are false will not be
/// present in the dictionary. See this link on how to construct a proper attributes string:
/// https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html
///
/// Note: this method doesn't work properly for certain type encodings, and neither does
/// the property_copyAttributeValue function in the runtime itself. Radar: FB7499230
- (NSDictionary *)propertyAttributes;
@end

View File

@@ -0,0 +1,75 @@
//
// NSString+ObjcRuntime.m
// FLEX
//
// Derived from MirrorKit.
// Created by Tanner on 7/1/15.
// Copyright (c) 2020 FLEX Team. All rights reserved.
//
#import "NSString+ObjcRuntime.h"
#import "FLEXRuntimeUtility.h"
@implementation NSString (Utilities)
- (NSString *)stringbyDeletingCharacterAtIndex:(NSUInteger)idx {
NSMutableString *string = self.mutableCopy;
[string replaceCharactersInRange:NSMakeRange(idx, 1) withString:@""];
return string;
}
/// See this link on how to construct a proper attributes string:
/// https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html
- (NSDictionary *)propertyAttributes {
if (!self.length) return nil;
NSMutableDictionary *attributes = [NSMutableDictionary new];
NSArray *components = [self componentsSeparatedByString:@","];
for (NSString *attribute in components) {
FLEXPropertyAttribute c = (FLEXPropertyAttribute)[attribute characterAtIndex:0];
switch (c) {
case FLEXPropertyAttributeTypeEncoding:
// Note: the type encoding here is not always correct. Radar: FB7499230
attributes[kFLEXPropertyAttributeKeyTypeEncoding] = [attribute stringbyDeletingCharacterAtIndex:0];
break;
case FLEXPropertyAttributeBackingIvarName:
attributes[kFLEXPropertyAttributeKeyBackingIvarName] = [attribute stringbyDeletingCharacterAtIndex:0];
break;
case FLEXPropertyAttributeCopy:
attributes[kFLEXPropertyAttributeKeyCopy] = @YES;
break;
case FLEXPropertyAttributeCustomGetter:
attributes[kFLEXPropertyAttributeKeyCustomGetter] = [attribute stringbyDeletingCharacterAtIndex:0];
break;
case FLEXPropertyAttributeCustomSetter:
attributes[kFLEXPropertyAttributeKeyCustomSetter] = [attribute stringbyDeletingCharacterAtIndex:0];
break;
case FLEXPropertyAttributeDynamic:
attributes[kFLEXPropertyAttributeKeyDynamic] = @YES;
break;
case FLEXPropertyAttributeGarbageCollectible:
attributes[kFLEXPropertyAttributeKeyGarbageCollectable] = @YES;
break;
case FLEXPropertyAttributeNonAtomic:
attributes[kFLEXPropertyAttributeKeyNonAtomic] = @YES;
break;
case FLEXPropertyAttributeOldTypeEncoding:
attributes[kFLEXPropertyAttributeKeyOldStyleTypeEncoding] = [attribute stringbyDeletingCharacterAtIndex:0];
break;
case FLEXPropertyAttributeReadOnly:
attributes[kFLEXPropertyAttributeKeyReadOnly] = @YES;
break;
case FLEXPropertyAttributeRetain:
attributes[kFLEXPropertyAttributeKeyRetain] = @YES;
break;
case FLEXPropertyAttributeWeak:
attributes[kFLEXPropertyAttributeKeyWeak] = @YES;
break;
}
}
return attributes;
}
@end

View File

@@ -0,0 +1,23 @@
//
// UIView+FLEX_Layout.h
// FLEX
//
// Created by Tanner Bennett on 7/18/19.
// Copyright © 2020 FLEX Team. All rights reserved.
//
#import <UIKit/UIKit.h>
#define Padding(p) UIEdgeInsetsMake(p, p, p, p)
@interface UIView (FLEX_Layout)
- (void)flex_centerInView:(UIView *)view;
- (void)flex_pinEdgesTo:(UIView *)view;
- (void)flex_pinEdgesTo:(UIView *)view withInsets:(UIEdgeInsets)insets;
- (void)flex_pinEdgesToSuperview;
- (void)flex_pinEdgesToSuperviewWithInsets:(UIEdgeInsets)insets;
- (void)flex_pinEdgesToSuperviewWithInsets:(UIEdgeInsets)insets aboveView:(UIView *)sibling;
- (void)flex_pinEdgesToSuperviewWithInsets:(UIEdgeInsets)insets belowView:(UIView *)sibling;
@end

View File

@@ -0,0 +1,66 @@
//
// UIView+FLEX_Layout.m
// FLEX
//
// Created by Tanner Bennett on 7/18/19.
// Copyright © 2020 FLEX Team. All rights reserved.
//
#import "UIView+FLEX_Layout.h"
@implementation UIView (FLEX_Layout)
- (void)flex_centerInView:(UIView *)view {
[NSLayoutConstraint activateConstraints:@[
[self.centerXAnchor constraintEqualToAnchor:view.centerXAnchor],
[self.centerYAnchor constraintEqualToAnchor:view.centerYAnchor],
]];
}
- (void)flex_pinEdgesTo:(UIView *)view {
[NSLayoutConstraint activateConstraints:@[
[self.topAnchor constraintEqualToAnchor:view.topAnchor],
[self.leftAnchor constraintEqualToAnchor:view.leftAnchor],
[self.bottomAnchor constraintEqualToAnchor:view.bottomAnchor],
[self.rightAnchor constraintEqualToAnchor:view.rightAnchor],
]];
}
- (void)flex_pinEdgesTo:(UIView *)view withInsets:(UIEdgeInsets)i {
[NSLayoutConstraint activateConstraints:@[
[self.topAnchor constraintEqualToAnchor:view.topAnchor constant:i.top],
[self.leftAnchor constraintEqualToAnchor:view.leftAnchor constant:i.left],
[self.bottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:-i.bottom],
[self.rightAnchor constraintEqualToAnchor:view.rightAnchor constant:-i.right],
]];
}
- (void)flex_pinEdgesToSuperview {
[self flex_pinEdgesTo:self.superview];
}
- (void)flex_pinEdgesToSuperviewWithInsets:(UIEdgeInsets)insets {
[self flex_pinEdgesTo:self.superview withInsets:insets];
}
- (void)flex_pinEdgesToSuperviewWithInsets:(UIEdgeInsets)i aboveView:(UIView *)sibling {
UIView *view = self.superview;
[NSLayoutConstraint activateConstraints:@[
[self.topAnchor constraintEqualToAnchor:view.topAnchor constant:i.top],
[self.leftAnchor constraintEqualToAnchor:view.leftAnchor constant:i.left],
[self.bottomAnchor constraintEqualToAnchor:sibling.topAnchor constant:-i.bottom],
[self.rightAnchor constraintEqualToAnchor:view.rightAnchor constant:-i.right],
]];
}
- (void)flex_pinEdgesToSuperviewWithInsets:(UIEdgeInsets)i belowView:(UIView *)sibling {
UIView *view = self.superview;
[NSLayoutConstraint activateConstraints:@[
[self.topAnchor constraintEqualToAnchor:sibling.bottomAnchor constant:i.top],
[self.leftAnchor constraintEqualToAnchor:view.leftAnchor constant:i.left],
[self.bottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:-i.bottom],
[self.rightAnchor constraintEqualToAnchor:view.rightAnchor constant:-i.right],
]];
}
@end