cocoa reference: Documentation for the Honeybadger Cocoa client library (SDK) and platform.
# Honeybadger for iOS and MacOS
> Honeybadger monitors your iOS and macOS apps for errors and exceptions so that you can fix them wicked fast.
**Typical installation time:** \~5 minutes Hi there! You’ve found Honeybadger’s guide to **Cocoa exception and error tracking for iOS and MacOS**. Once installed, Honeybadger will automatically report errors in your iOS/macOS application. ## Getting started [Section titled “Getting started”](#getting-started) ### CocoaPods [Section titled “CocoaPods”](#cocoapods) To install via CocoaPods, create/open your **Pods** file and add a pod entry for **‘Honeybadger’**. Make sure **use\_frameworks!** is specified.
```shell
use_frameworks!
target 'MyApp' do
pod 'Honeybadger'
end
```
### Swift Package Manager [Section titled “Swift Package Manager”](#swift-package-manager) Open your app in Xcode, then go to **File** > **Swift Packages** > **Add Package Dependency**, and specify the Honeybadger Cocoa GitHub repo: **** ### Initialization [Section titled “Initialization”](#initialization) You will need your Honeybadger API key to initialize the Honeybadger library. You can log into your [Honeybadger](https://honeybadger.io) account to obtain your API key. In your App Delegate, import the Honeybadger library: #### Swift [Section titled “Swift”](#swift)
```swift
import Honeybadger
```
#### Objective-C [Section titled “Objective-C”](#objective-c)
```objc
@import Honeybadger;
```
In your `didFinishLaunchingWithOptions` method, add the following code to initialize Honeybadger: #### Swift [Section titled “Swift”](#swift-1)
```swift
Honeybadger.configure(apiKey:"PROJECT_API_KEY")
```
#### Objective-C [Section titled “Objective-C”](#objective-c-1)
```objc
[Honeybadger configureWithAPIKey:@"PROJECT_API_KEY"];
```
## Usage examples [Section titled “Usage examples”](#usage-examples) Errors and exceptions will be automatically handled by the Honeybadger library, but you can also use the following API to customize error handling in your application. ### notify [Section titled “notify”](#notify) You can use the **notify** methods to manually send an error as a string or Error/NSError object. If available, the Honeybadger library will attempt to extract a stack trace and any relevant information that might be useful. You can also optionally provide **context**, to include any relevant information about the error. #### Swift [Section titled “Swift”](#swift-2)
```swift
Honeybadger.notify(
errorString: "My error"
);
Honeybadger.notify(
errorString: "My error",
context: ["user_id" : "123abc"]
);
Honeybadger.notify(
error: MyError("This is my custom error.")
);
Honeybadger.notify(
error: MyError("This is my custom error."),
context: ["user_id" : "123abc"]
);
```
#### Objective-C [Section titled “Objective-C”](#objective-c-2)
```objc
[Honeybadger notifyWithString:@"My error"];
[Honeybadger
notifyWithString:@"My error"
context:@{ @"user_id" : @"123abc" }
];
[Honeybadger notifyWithError:
[[NSError alloc] initWithDomain:@"my.test.error" code:-1 userInfo: @{}]
];
[Honeybadger
notifyWithError:[[NSError alloc] initWithDomain:@"my.test.error" code:-1 userInfo: @{}]
context:@{ @"user_id" : @"123abc" }
];
```
### setContext [Section titled “setContext”](#setcontext) If you have data that you would like to include whenever an error or an exception occurs, you can provide that data using the **setContext** method. You can call **setContext** as many times as needed. New context data will be merged with any previously-set context data. #### Swift [Section titled “Swift”](#swift-3)
```swift
Honeybadger.setContext(context: ["user_id" : "123abc"]);
```
#### Objective-C [Section titled “Objective-C”](#objective-c-3)
```objc
[Honeybadger setContext:@{@"user_id" : @"123abc"}];
```
### resetContext [Section titled “resetContext”](#resetcontext) If you’ve used **setContext** to store data, you can use **resetContext** to clear that data. #### Swift [Section titled “Swift”](#swift-4)
```swift
Honeybadger.resetContext();
```
#### Objective-C [Section titled “Objective-C”](#objective-c-4)
```objc
[Honeybadger setContext];
```