diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3552f2b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.swiftpm diff --git a/Package.swift b/Package.swift index 7731bc7..397097f 100644 --- a/Package.swift +++ b/Package.swift @@ -22,6 +22,7 @@ let package = Package( "swift_shims", ], path: "Sources/FNZombie", + publicHeadersPath: "include", cSettings: [ .headerSearchPath("include"), .unsafeFlags(["-fno-objc-arc"]) diff --git a/README.md b/README.md index 8f4a2fd..aa63294 100644 --- a/README.md +++ b/README.md @@ -1 +1,46 @@ # FNZombie + +Custom implementation of zombie objects for debugging bad access crashes. This library is an alternative, more customizable implementation of Apple's built-in `NSZombie`. + +Please see: +* https://funcorp.dev/blog/stopping_nszombie_invasion +* https://developer.apple.com/documentation/xcode/investigating-memory-access-crashes +* https://developer.apple.com/documentation/xcode/investigating-crashes-for-zombie-objects + +How to call from a Swift app: + +Import the SwiftPM package: +```swift +let package = Package( + // ... + dependencies: [ + .package(url: "https://github.com/funcorp/FNZombie.git", .branch("master")) + ], + targets: [ + .target( + name: "", + dependencies: [ + .product(name: "FNZombie", package: "FNZombie") + ] + ) + ] +) +``` + +Import the package somewhere early on in your init and initialize the zombie service, ex: + +```swift +import FNZombie + +@main +class MyAppDelegate: iOSHostApplication { + + override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + + FNZombieService.sharedInstance().enable(withBufferSize: 128) // This buffer size can be whatever you want + + } +} +``` + +Now, run your app and check the logs for any zombie object calls when the app crashes. \ No newline at end of file diff --git a/Sources/FNZombie/FNZombie.h b/Sources/FNZombie/FNZombie.h index 7979ecf..fa869b1 100644 --- a/Sources/FNZombie/FNZombie.h +++ b/Sources/FNZombie/FNZombie.h @@ -27,6 +27,8 @@ __attribute__((objc_root_class)) withObject:(id)anArgument afterDelay:(NSTimeInterval)delay; +- (IMP) methodForSelector:(SEL) aSelector; + @end #endif /* FNZombie_h */ diff --git a/Sources/FNZombie/FNZombieService.m b/Sources/FNZombie/FNZombieService.m index fa61346..79a99fc 100644 --- a/Sources/FNZombie/FNZombieService.m +++ b/Sources/FNZombie/FNZombieService.m @@ -321,4 +321,12 @@ - (void)performSelector:(SEL)aSelector ]; }; +- (IMP) methodForSelector:(SEL) aSelector { + [[FNZombieService sharedInstance] + crashWithObject:self + withSelector:aSelector + fromSelector:_cmd + ]; +} + @end