kstenerud / KSCrash

The Ultimate iOS Crash Reporter
MIT License
4.23k stars 705 forks source link

Swiftify API #504

Closed GLinnik21 closed 2 months ago

GLinnik21 commented 2 months ago

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.