# Using the Superwall Delegate

Use Superwall's delegate to extend our SDK's functionality across several surface areas by assigning to the `delegate` property:

:::ios
## Tab

```swift Swift
class SWDelegate: SuperwallDelegate {
    // Implement delegate methods here
}

// After configuring the SDK...
Superwall.shared.delegate = SWDelegate()
```

## Tab

```swift Objective-C
// In its own file...
#import <Foundation/Foundation.h>
@import SuperwallKit;
@interface SWDelegate : NSObject <SWKSuperwallDelegate>
@end
@implementation SWDelegate
    // Implement delegate methods here
@end

// After configuring the SDK...
[[Superwall sharedInstance] setDelegate:[SWDelegate new]];
```


:::

Some common use cases for using the Superwall delegate include:

* **Custom actions:** [Respond to custom tap actions from a paywall.](/docs/sdk/guides/advanced/custom-paywall-actions#custom-paywall-actions)
* **Respond to purchases:** [See which product was purchased from the presented paywall.](/docs/sdk/guides/advanced/viewing-purchased-products)
* **Analytics:** [Forward events from Superwall to your own analytics.](/docs/sdk/guides/3rd-party-analytics)

Below are some commonly used implementations when using the delegate.

Superwall Events [#superwall-events]

Most of what occurs in Superwall can be viewed using the delegate method to respond to events:

:::ios
## Tab

```swift Swift
class SWDelegate: SuperwallDelegate {
  func handleSuperwallEvent(withInfo eventInfo: SuperwallEventInfo) {
    switch eventInfo.event {
    case .transactionComplete(let transaction, let product, let paywallInfo):
      print("Converted from paywall originalTransactionIdentifier: \(transaction?.originalTransactionIdentifier ?? "")")
      print("Converted from paywall storeTransactionId: \(transaction?.storeTransactionId ?? "")")
      print("Converted from paywall productIdentifier: \(product.productIdentifier)")
      print("Converted from paywall paywallInfo: \(paywallInfo.identifier)")
    case .transactionRestore(let restoreType, let paywallInfo):
      print("transactionRestore restoreType \(restoreType)")
    case let .customPlacement(name, params, paywallInfo):
      // Forward Mixpanel/Ampltiude/etc
      print("\(name) - \(params) - \(paywallInfo)")
    default:
      // And several more events to use...
      print("Default event: \(eventInfo.event.description)")
    }
  }
}
```

## Tab

```swift Objective-C
// SWDelegate.h...
#import <Foundation/Foundation.h>
@import SuperwallKit;

NS_ASSUME_NONNULL_BEGIN

@interface SWDelegate : NSObject <SWKSuperwallDelegate>

@end

NS_ASSUME_NONNULL_END

// SWDelegate.m...
@implementation SWDelegate

- (void)handleSuperwallEventWithInfo:(SWKSuperwallEventInfo *)eventInfo {
  switch(eventInfo.event) {
    // Switch on any event type here...
    case SWKSuperwallEventTransactionComplete:
      NSLog(@"Transaction complete: %@", eventInfo.params[@"primary_product_id"]);
  }
}
```


:::

Paywall Custom Actions [#paywall-custom-actions]

Using the [custom tap action](/docs/sdk/guides/advanced/custom-paywall-actions#custom-paywall-actions), you can respond to any arbitrary event from a paywall:

:::ios
## Tab

```swift Swift
class SWDelegate: SuperwallDelegate {
  func handleCustomPaywallAction(withName name: String) {
    if name == "showHelpCenter" {
      DispatchQueue.main.asyncAfter(deadline: .now() + 0.33) {
        self.showHelpCenter.toggle()
      }
    }
  }
}
```

## Tab

```swift Objective-C
// SWDelegate.h...
#import <Foundation/Foundation.h>
@import SuperwallKit;

NS_ASSUME_NONNULL_BEGIN

@interface SWDelegate : NSObject <SWKSuperwallDelegate>

@end

NS_ASSUME_NONNULL_END

// SWDelegate.m...
#import "SWDelegate.h"

@implementation SWDelegate

- (void)handleCustomPaywallActionWithName:(NSString *)name {
  if ([name isEqualToString:@"showHelpCenter"]) {
   [self showHelpCenter];
  }
}

@end
```


:::

Subscription status changes [#subscription-status-changes]

You can be informed of subscription status changes using the delegate. If you need to set or handle the status on your own, use a [purchase controller](/docs/sdk/guides/advanced-configuration) — this function is only for informational, tracking or similar purposes:

:::ios
## Tab

```swift Swift
class SWDelegate: SuperwallDelegate {
  func subscriptionStatusDidChange(from oldValue: SubscriptionStatus, to newValue: SubscriptionStatus) {
    // Log or handle subscription change in your Ui
  }
}
```

## Tab

```swift Objective-C
// SWDelegate.h...
#import <Foundation/Foundation.h>
@import SuperwallKit;

NS_ASSUME_NONNULL_BEGIN

@interface SWDelegate : NSObject <SWKSuperwallDelegate>

@end

NS_ASSUME_NONNULL_END

// SWDelegate.m...
@implementation SWDelegate
- (void)subscriptionStatusDidChangeFrom:(enum SWKSubscriptionStatus)oldValue
                                     to:(enum SWKSubscriptionStatus)newValue {
  NSLog(@"Changed from %lu to %lu", (unsigned long)oldValue, (unsigned long)newValue);
}
@end
```


:::

Paywall events [#paywall-events]

The delegate also has callbacks for several paywall events, such dismissing, presenting, and more. Here's an example:

:::ios
## Tab

```swift Swift
class SWDelegate: SuperwallDelegate {
  func didPresentPaywall(withInfo paywallInfo: PaywallInfo) {
    // paywallInfo will contain all of the presented paywall's info
  }
}
```

## Tab

```swift Objective-C
// SWDelegate.h...
#import <Foundation/Foundation.h>
@import SuperwallKit;

NS_ASSUME_NONNULL_BEGIN

@interface SWDelegate : NSObject <SWKSuperwallDelegate>

@end

NS_ASSUME_NONNULL_END

// SWDelegate.m...
@implementation SWDelegate
- (void)didPresentPaywallWithInfo:(SWKPaywallInfo *)paywallInfo {
  NSLog(@"Presented paywall with info: %@", paywallInfo);
}
@end
```


:::