Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swiftify API #504

Merged
merged 33 commits into from
Jun 23, 2024
Merged

Swiftify API #504

merged 33 commits into from
Jun 23, 2024

Conversation

GLinnik21
Copy link
Collaborator

@GLinnik21 GLinnik21 commented Jun 18, 2024

This PR introduces significant updates to the KSCrash library, focusing on enhancing compatibility with Swift, modernizing the Objective-C code, and improving maintainability. Below are the key changes made:

Major Changes:

  1. Swift-Compatible Initializers and Methods:
    • Replaced all class and instance initializers with instancetype to ensure better compatibility and consistency across Swift and Objective-C. This change improves type safety and makes the codebase more modern and reliable.
  2. Introduction of Nullable Annotations:
    • Applied nullable annotations to parameters and return types, where applicable, to clarify which values can be nil. This change is crucial for Swift interoperability, reducing potential runtime errors and improving code clarity.
  3. Refactor Enums to NS_ENUM:
    • Updated traditional C-style enums to NS_ENUM to enhance type safety and facilitate smoother integration with Swift. This modification allows enums to be used more effectively in Swift, leveraging the language's type system for better safety and usability.
  4. Modernized Key Access Syntax:
    • Replaced legacy @KSCrashField_XXX string literal access with KSCrashField_XXX constants to align with contemporary Objective-C practices. This change reduces the risk of errors associated with string literals and ensures a more maintainable codebase.
  5. Swift-Friendly Naming Conventions:
    • Added NS_SWIFT_NAME annotations to key methods and properties to provide more intuitive names when accessed from Swift. This improves the developer experience, making the API more natural and easier to use in Swift projects.

@GLinnik21 GLinnik21 marked this pull request as ready for review June 20, 2024 15:33
@GLinnik21 GLinnik21 requested a review from bamx23 June 20, 2024 15:33
@GLinnik21 GLinnik21 mentioned this pull request Jun 20, 2024
11 tasks
Sources/KSCrashFilters/KSCrashReportFilterBasic.m Outdated Show resolved Hide resolved
* used to store the output of its respective filter in the final
* report dictionary.
*/
+ (instancetype) filterWithFilters:(NSArray*) filters keys:(NSArray<NSString*>*) keys;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind providing a type to array?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't. Here is a bad legacy design, where we can pass array of objects or array of arrays. From doc:

 * @param filters An array of filters to apply. Each filter should conform to the
 *                KSCrashReportFilter protocol. If a filter is an NSArray, it will
 *                be wrapped in a pipeline filter.

@@ -56,15 +61,37 @@
* Each "filter" can be id<KSCrashReportFilter> or an NSArray
* of filters (which gets wrapped in a pipeline filter).
*/
+ (KSCrashReportFilterCombine*) filterWithFiltersAndKeys:(id) firstFilter, ... NS_REQUIRES_NIL_TERMINATION;
+ (instancetype) filterWithFiltersAndKeys:(nullable id) firstFilter, ... NS_REQUIRES_NIL_TERMINATION;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we drop nil-termenated initialization? Not sure if it's used anywhere, but maybe it's just me

Copy link
Collaborator Author

@GLinnik21 GLinnik21 Jun 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's visible for C, but not for Swift, that's why a implemented with NSArray side-by-side.

Sources/KSCrashInstallations/include/KSCrashInstallation.h Outdated Show resolved Hide resolved
Sources/KSCrashRecording/include/KSCrashAppMemory.h Outdated Show resolved Hide resolved
Comment on lines +239 to +241
KSCRF_DEFINE_CONSTANT(KSCrashField, BuildType, buildType, "build_type")

KSCRF_DEFINE_CONSTANT(KSCrashField, MemoryFootprint, memoryFootprint, "memory_footprint")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also split KSCrashField into smaller groups?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about it, but I didn't want to break the names.

Sources/KSCrashSinks/KSCrashReportSinkQuincyHockey.m Outdated Show resolved Hide resolved
Sources/KSCrashSinks/KSCrashReportSinkQuincyHockey.m Outdated Show resolved Hide resolved
GLinnik21 and others added 4 commits June 23, 2024 00:16
…essary copy

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

Co-authored-by: Nikolay Volosatov <code@bamx23.com>
@GLinnik21 GLinnik21 requested a review from bamx23 June 22, 2024 23:16
@bamx23 bamx23 merged commit f189d62 into master Jun 23, 2024
19 checks passed
@GLinnik21 GLinnik21 deleted the swiftify-api branch June 24, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants