Skip to content

Commit

Permalink
Swiftify API (#504)
Browse files Browse the repository at this point in the history
* Fixes and nullability in `KSCrash.h`

* Update `KSCrashAppTransitionState` API

* Swiftify KSCrashReportFields

* Remove boilerplate in ReportFields

* Rename to `sharedInstance` in `KSCrashAppStateTracker`

* Swiftify `KSCrash.h`

* Swiftify `KSCrashAppMemory.h`

* Swiftify `KSCrashAppMemoryTracker.h`

* Swiftify `KSCrashAppStateTracker.h`

* Swiftify `KSCrashAppTransitionState.h`

* Swiftify `KSCrashConfiguration.h`

* Swiftify `KSCrashMonitorType.h`

* Swiftify `KSCrashReportFields.h`

* Swiftify `KSCrashReportFilter.h`

* Swiftify `KSCrashReportWriter.h`

* Fix Integer types

* Swiftify `KSCrashReportFilterAlert.h`

* Swiftify `KSCrashReportFilterAppleFmt.h`

* Swiftify `KSCrashReportFilterBasic.h`

* Swiftify `KSCrashReportFilterGZip.h`

* Remove duplicate declaration in `KSCrashReportFilterBasic.m`

* Swiftify `KSCrashReportFilterJSON.h`

* Swiftify `KSCrashReportFilterSets.h`

* Swiftify `KSCrashReportFilterStringify.h`

* Swiftify `Sinks`

* Swiftify `Installations`

* Use `instancetype` everywhere. Use ARC property specifiers

* Fix failing tests and nullability warnings

* Refactor filter assignment to use direct ivar access and remove unnecessary copy

Co-authored-by: Nikolay Volosatov <code@bamx23.com>

* Adjust NS_SWIFT_NAME macro placement for clarity

Co-authored-by: Nikolay Volosatov <code@bamx23.com>

* Refactor property attributes: switch from retain to copy/strong for appropriate types

Co-authored-by: Nikolay Volosatov <code@bamx23.com>

* Fix formatting issue in sinkWithURL: method declaration

* Update `NS_SWIFT_NAME` attributes to more descriptive names across Installations

---------

Co-authored-by: Nikolay Volosatov <code@bamx23.com>
  • Loading branch information
GLinnik21 and bamx23 authored Jun 23, 2024
1 parent 93fd37c commit f189d62
Show file tree
Hide file tree
Showing 52 changed files with 1,012 additions and 694 deletions.
16 changes: 8 additions & 8 deletions Sources/KSCrashFilters/KSCrashReportFilterAlert.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,21 @@ @implementation KSCrashReportFilterAlert
@synthesize yesAnswer = _yesAnswer;
@synthesize noAnswer = _noAnswer;

+ (KSCrashReportFilterAlert*) filterWithTitle:(NSString*) title
message:(NSString*) message
yesAnswer:(NSString*) yesAnswer
noAnswer:(NSString*) noAnswer
+ (instancetype) filterWithTitle:(NSString*) title
message:(nullable NSString*) message
yesAnswer:(NSString*) yesAnswer
noAnswer:(nullable NSString*) noAnswer;
{
return [[self alloc] initWithTitle:title
message:message
yesAnswer:yesAnswer
noAnswer:noAnswer];
}

- (id) initWithTitle:(NSString*) title
message:(NSString*) message
yesAnswer:(NSString*) yesAnswer
noAnswer:(NSString*) noAnswer
- (instancetype) initWithTitle:(NSString*) title
message:(nullable NSString*) message
yesAnswer:(NSString*) yesAnswer
noAnswer:(nullable NSString*) noAnswer;
{
if((self = [super init]))
{
Expand Down
220 changes: 111 additions & 109 deletions Sources/KSCrashFilters/KSCrashReportFilterAppleFmt.m

Large diffs are not rendered by default.

67 changes: 41 additions & 26 deletions Sources/KSCrashFilters/KSCrashReportFilterBasic.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

@implementation KSCrashReportFilterPassthrough

+ (KSCrashReportFilterPassthrough*) filter
+ (instancetype) filter
{
return [[self alloc] init];
}
Expand All @@ -55,8 +55,6 @@ @interface KSCrashReportFilterCombine ()
@property(nonatomic,readwrite,retain) NSArray* filters;
@property(nonatomic,readwrite,retain) NSArray* keys;

- (id) initWithFilters:(NSArray*) filters keys:(NSArray*) keys;

@end


Expand All @@ -65,7 +63,7 @@ @implementation KSCrashReportFilterCombine
@synthesize filters = _filters;
@synthesize keys = _keys;

- (id) initWithFilters:(NSArray*) filters keys:(NSArray*) keys
- (instancetype) initWithFilters:(NSArray*) filters keys:(NSArray<NSString*>*) keys
{
if((self = [super init]))
{
Expand Down Expand Up @@ -113,15 +111,20 @@ + (KSVA_Block) argBlockWithFilters:(NSMutableArray*) filters andKeys:(NSMutableA
return [block copy];
}

+ (KSCrashReportFilterCombine*) filterWithFiltersAndKeys:(id) firstFilter, ...
+ (instancetype) filterWithFiltersAndKeys:(id) firstFilter, ...
{
NSMutableArray* filters = [NSMutableArray array];
NSMutableArray* keys = [NSMutableArray array];
ksva_iterate_list(firstFilter, [self argBlockWithFilters:filters andKeys:keys]);
return [[self class] filterWithFilters:filters keys:keys];
}

+ (instancetype)filterWithFilters:(NSArray*)filters keys:(NSArray<NSString*>*)keys
{
return [[self alloc] initWithFilters:filters keys:keys];
}

- (id) initWithFiltersAndKeys:(id) firstFilter, ...
- (instancetype) initWithFiltersAndKeys:(id) firstFilter, ...
{
NSMutableArray* filters = [NSMutableArray array];
NSMutableArray* keys = [NSMutableArray array];
Expand Down Expand Up @@ -233,7 +236,7 @@ - (void) filterReports:(NSArray*) reports

@interface KSCrashReportFilterPipeline ()

@property(nonatomic,readwrite,retain) NSArray* filters;
@property(nonatomic,readwrite,copy) NSArray<id<KSCrashReportFilter>>* filters;

@end

Expand All @@ -242,19 +245,24 @@ @implementation KSCrashReportFilterPipeline

@synthesize filters = _filters;

+ (KSCrashReportFilterPipeline*) filterWithFilters:(id) firstFilter, ...
+ (instancetype) filterWithFilters:(id) firstFilter, ...
{
ksva_list_to_nsarray(firstFilter, filters);
return [[self class] filterWithFiltersArray:filters];
}

+ (instancetype) filterWithFiltersArray:(NSArray*) filters
{
return [[self alloc] initWithFiltersArray:filters];
}

- (id) initWithFilters:(id) firstFilter, ...
- (instancetype) initWithFilters:(id) firstFilter, ...
{
ksva_list_to_nsarray(firstFilter, filters);
return [self initWithFiltersArray:filters];
}

- (id) initWithFiltersArray:(NSArray*) filters
- (instancetype) initWithFiltersArray:(NSArray*) filters
{
if((self = [super init]))
{
Expand All @@ -270,15 +278,14 @@ - (id) initWithFiltersArray:(NSArray*) filters
[expandedFilters addObject:filter];
}
}
self.filters = expandedFilters;
_filters = [expandedFilters copy];
}
return self;
}

- (void) addFilter:(id<KSCrashReportFilter>) filter
{
NSMutableArray* mutableFilters = (NSMutableArray*)self.filters; // Shh! Don't tell anyone!
[mutableFilters insertObject:filter atIndex:0];
self.filters = [@[filter] arrayByAddingObjectsFromArray:self.filters];
}

- (void) filterReports:(NSArray*) reports
Expand Down Expand Up @@ -363,14 +370,12 @@ @implementation KSCrashReportFilterObjectForKey
@synthesize key = _key;
@synthesize allowNotFound = _allowNotFound;

+ (KSCrashReportFilterObjectForKey*) filterWithKey:(id)key
allowNotFound:(BOOL) allowNotFound
+ (instancetype) filterWithKey:(id)key allowNotFound:(BOOL) allowNotFound
{
return [[self alloc] initWithKey:key allowNotFound:allowNotFound];
}

- (id) initWithKey:(id)key
allowNotFound:(BOOL) allowNotFound
- (instancetype) initWithKey:(id)key allowNotFound:(BOOL) allowNotFound
{
if((self = [super init]))
{
Expand Down Expand Up @@ -421,7 +426,7 @@ - (void) filterReports:(NSArray*) reports
@interface KSCrashReportFilterConcatenate ()

@property(nonatomic, readwrite, retain) NSString* separatorFmt;
@property(nonatomic, readwrite, retain) NSArray* keys;
@property(nonatomic, readwrite, retain) NSArray<NSString*>* keys;

@end

Expand All @@ -430,19 +435,24 @@ @implementation KSCrashReportFilterConcatenate
@synthesize separatorFmt = _separatorFmt;
@synthesize keys = _keys;

+ (KSCrashReportFilterConcatenate*) filterWithSeparatorFmt:(NSString*) separatorFmt keys:(id) firstKey, ...
+ (instancetype) filterWithSeparatorFmt:(NSString*) separatorFmt keys:(id) firstKey, ...
{
ksva_list_to_nsarray(firstKey, keys);
return [[self class] filterWithSeparatorFmt:separatorFmt keysArray:keys];
}

+ (instancetype) filterWithSeparatorFmt:(NSString*) separatorFmt keysArray:(NSArray<NSString*>*) keys
{
return [[self alloc] initWithSeparatorFmt:separatorFmt keysArray:keys];
}

- (id) initWithSeparatorFmt:(NSString*) separatorFmt keys:(id) firstKey, ...
- (instancetype) initWithSeparatorFmt:(NSString*) separatorFmt keys:(id) firstKey, ...
{
ksva_list_to_nsarray(firstKey, keys);
return [self initWithSeparatorFmt:separatorFmt keysArray:keys];
}

- (id) initWithSeparatorFmt:(NSString*) separatorFmt keysArray:(NSArray*) keys
- (instancetype) initWithSeparatorFmt:(NSString*) separatorFmt keysArray:(NSArray<NSString*>*) keys
{
if((self = [super init]))
{
Expand Down Expand Up @@ -504,19 +514,24 @@ @implementation KSCrashReportFilterSubset

@synthesize keyPaths = _keyPaths;

+ (KSCrashReportFilterSubset*) filterWithKeys:(id) firstKeyPath, ...
+ (instancetype) filterWithKeys:(id) firstKeyPath, ...
{
ksva_list_to_nsarray(firstKeyPath, keyPaths);
return [[self class] filterWithKeysArray:keyPaths];
}

+ (instancetype) filterWithKeysArray:(NSArray<NSString*>*) keyPaths
{
return [[self alloc] initWithKeysArray:keyPaths];
}

- (id) initWithKeys:(id) firstKeyPath, ...
- (instancetype) initWithKeys:(id) firstKeyPath, ...
{
ksva_list_to_nsarray(firstKeyPath, keyPaths);
return [self initWithKeysArray:keyPaths];
}

- (id) initWithKeysArray:(NSArray*) keyPaths
- (instancetype) initWithKeysArray:(NSArray<NSString*>*) keyPaths
{
if((self = [super init]))
{
Expand Down Expand Up @@ -568,7 +583,7 @@ - (void) filterReports:(NSArray*) reports

@implementation KSCrashReportFilterDataToString

+ (KSCrashReportFilterDataToString*) filter
+ (instancetype) filter
{
return [[self alloc] init];
}
Expand All @@ -591,7 +606,7 @@ - (void) filterReports:(NSArray*) reports

@implementation KSCrashReportFilterStringToData

+ (KSCrashReportFilterStringToData*) filter
+ (instancetype) filter
{
return [[self alloc] init];
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/KSCrashFilters/KSCrashReportFilterGZip.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@

@interface KSCrashReportFilterGZipCompress ()

@property(nonatomic,readwrite,assign) int compressionLevel;
@property(nonatomic,readwrite,assign) NSInteger compressionLevel;

@end

@implementation KSCrashReportFilterGZipCompress

@synthesize compressionLevel = _compressionLevel;

+ (KSCrashReportFilterGZipCompress*) filterWithCompressionLevel:(int) compressionLevel
+ (instancetype) filterWithCompressionLevel:(NSInteger) compressionLevel
{
return [[self alloc] initWithCompressionLevel:compressionLevel];
}

- (id) initWithCompressionLevel:(int) compressionLevel
- (instancetype) initWithCompressionLevel:(NSInteger) compressionLevel
{
if((self = [super init]))
{
Expand All @@ -60,7 +60,7 @@ - (void) filterReports:(NSArray*) reports
for(NSData* report in reports)
{
NSError* error = nil;
NSData* compressedData = [report gzippedWithCompressionLevel:self.compressionLevel
NSData* compressedData = [report gzippedWithCompressionLevel:(int)self.compressionLevel
error:&error];
if(compressedData == nil)
{
Expand All @@ -81,7 +81,7 @@ - (void) filterReports:(NSArray*) reports

@implementation KSCrashReportFilterGZipDecompress

+ (KSCrashReportFilterGZipDecompress*) filter
+ (instancetype) filter
{
return [[self alloc] init];
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/KSCrashFilters/KSCrashReportFilterJSON.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ @implementation KSCrashReportFilterJSONEncode

@synthesize encodeOptions = _encodeOptions;

+ (KSCrashReportFilterJSONEncode*) filterWithOptions:(KSJSONEncodeOption) options
+ (instancetype) filterWithOptions:(KSJSONEncodeOption) options
{
return [(KSCrashReportFilterJSONEncode*)[self alloc] initWithOptions:options];
return [[self alloc] initWithOptions:options];
}

- (id) initWithOptions:(KSJSONEncodeOption) options
- (instancetype) initWithOptions:(KSJSONEncodeOption) options
{
if((self = [super init]))
{
Expand Down Expand Up @@ -94,12 +94,12 @@ @implementation KSCrashReportFilterJSONDecode

@synthesize decodeOptions = _encodeOptions;

+ (KSCrashReportFilterJSONDecode*) filterWithOptions:(KSJSONDecodeOption) options
+ (instancetype) filterWithOptions:(KSJSONDecodeOption) options
{
return [(KSCrashReportFilterJSONDecode*)[self alloc] initWithOptions:options];
return [[self alloc] initWithOptions:options];
}

- (id) initWithOptions:(KSJSONDecodeOption) options
- (instancetype) initWithOptions:(KSJSONDecodeOption) options
{
if((self = [super init]))
{
Expand Down
4 changes: 2 additions & 2 deletions Sources/KSCrashFilters/KSCrashReportFilterSets.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ @implementation KSCrashFilterSets
id<KSCrashReportFilter> appleFilter = [KSCrashReportFilterAppleFmt filterWithReportStyle:reportStyle];
id<KSCrashReportFilter> userSystemFilter = [KSCrashReportFilterPipeline filterWithFilters:
[KSCrashReportFilterSubset filterWithKeys:
@KSCrashField_System,
@KSCrashField_User,
KSCrashField_System,
KSCrashField_User,
nil],
[KSCrashReportFilterJSONEncode filterWithOptions:KSJSONEncodeOptionPretty | KSJSONEncodeOptionSorted],
[KSCrashReportFilterDataToString filter],
Expand Down
2 changes: 1 addition & 1 deletion Sources/KSCrashFilters/KSCrashReportFilterStringify.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@implementation KSCrashReportFilterStringify

+ (KSCrashReportFilterStringify*) filter
+ (instancetype) filter
{
return [[self alloc] init];
}
Expand Down
20 changes: 12 additions & 8 deletions Sources/KSCrashFilters/include/KSCrashReportFilterAlert.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import <Foundation/Foundation.h>
#import "KSCrashReportFilter.h"

NS_ASSUME_NONNULL_BEGIN

/** Pops up a standard alert window and awaits a user response before continuing.
*
Expand All @@ -39,6 +40,7 @@
* Input: Any
* Output: Same as input (passthrough)
*/
NS_SWIFT_NAME(CrashReportFilterAlert)
@interface KSCrashReportFilterAlert : NSObject <KSCrashReportFilter>

/**
Expand All @@ -48,10 +50,10 @@
* @param noAnswer The text to put in the "no" button. If nil, the filter will
* proceed unconditionally.
*/
+ (KSCrashReportFilterAlert*) filterWithTitle:(NSString*) title
message:(NSString*) message
yesAnswer:(NSString*) yesAnswer
noAnswer:(NSString*) noAnswer;
+ (instancetype) filterWithTitle:(NSString*) title
message:(nullable NSString*) message
yesAnswer:(NSString*) yesAnswer
noAnswer:(nullable NSString*) noAnswer;

/**
* @param title The title of the alert.
Expand All @@ -60,9 +62,11 @@
* @param noAnswer The text to put in the "no" button. If nil, the filter will
* proceed unconditionally.
*/
- (id) initWithTitle:(NSString*) title
message:(NSString*) message
yesAnswer:(NSString*) yesAnswer
noAnswer:(NSString*) noAnswer;
- (instancetype) initWithTitle:(NSString*) title
message:(nullable NSString*) message
yesAnswer:(NSString*) yesAnswer
noAnswer:(nullable NSString*) noAnswer;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit f189d62

Please sign in to comment.