Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.swiftpm
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let package = Package(
"swift_shims",
],
path: "Sources/FNZombie",
publicHeadersPath: "include",
cSettings: [
.headerSearchPath("include"),
.unsafeFlags(["-fno-objc-arc"])
Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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: "<MY 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.
2 changes: 2 additions & 0 deletions Sources/FNZombie/FNZombie.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ __attribute__((objc_root_class))
withObject:(id)anArgument
afterDelay:(NSTimeInterval)delay;

- (IMP) methodForSelector:(SEL) aSelector;

@end

#endif /* FNZombie_h */
8 changes: 8 additions & 0 deletions Sources/FNZombie/FNZombieService.m
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,12 @@ - (void)performSelector:(SEL)aSelector
];
};

- (IMP) methodForSelector:(SEL) aSelector {
[[FNZombieService sharedInstance]
crashWithObject:self
withSelector:aSelector
fromSelector:_cmd
];
}

@end