---
title: iOS Buy SDK
description: Set up the iOS Buy SDK for product browsing and cart management.
source_url:
  html: 'https://shopify.dev/docs/storefronts/mobile/buy-sdk-ios'
  md: 'https://shopify.dev/docs/storefronts/mobile/buy-sdk-ios.md'
---

# i​OS Buy SDK

The iOS Buy SDK provides a typed Swift interface to the Storefront API. Use it to fetch products, manage carts, and produce a `checkoutUrl` you can hand to Checkout Kit.

***

## What the Buy SDK does

The Buy SDK wraps the Storefront API in typed Swift methods. Each capability has a recommended alternative:

| Task | Buy SDK | Alternative |
| - | - | - |
| Fetch products and collections | Yes (typed Swift interface) | Direct [Storefront API](https://shopify.dev/docs/api/storefront) calls |
| Create and manage carts | Yes (typed Swift interface) | Direct Storefront API calls |
| Present checkout | No (use Checkout Kit) | [Checkout Kit](https://shopify.dev/docs/storefronts/mobile/checkout-kit) |

***

## Requirements

* iOS 13.0 or higher.
* Xcode 14.0 or higher.
* Swift 5.7 or higher.
* A [Storefront API access token](https://shopify.dev/docs/storefronts/headless/building-with-the-storefront-api/getting-started).

***

## Step 1: Generate an access token

To generate an access token, you can [generate one in the Shopify admin](https://shopify.dev/docs/apps/build/authentication-authorization/legacy/admin-custom-apps). Alternatively, you can create a custom app and use [authorization code grant](https://shopify.dev/docs/apps/build/authentication-authorization/authenticate-standalone-apps).

***

## Step 2: Make your products and collections available

After you've generated an access token, you need to make products and collections available to your custom app to access them from your app. After the products and collections are available, you can retrieve them using their respective IDs.

**Tip:**

If you have many products or collections, then you can use [bulk actions](https://help.shopify.com/manual/shopify-admin/productivity-tools/bulk-actions) to make them available in one step.

### Make a product available

1. From your Shopify admin, go to **Products**.
2. From the **Products** page, click the product you want to make available.
3. Next to **SALES CHANNELS AND APPS** click **Manage**.
4. In the **Sales channels and apps** dialog box, select the box next to the name of your custom app.

### Make a collection available

1. From your Shopify admin, go to **Products** and click **Collections**.
2. From the **Collections** page, click the collection you want to make available.
3. Next to **SALES CHANNELS AND APPS** click **Manage**.
4. In the **Sales channels and apps** dialog box, select the box next to the name of your custom app.

***

## Step 3: Install the SDK

Add the Buy SDK to your project using Swift Package Manager:

## Package.swift

```swift
dependencies: [
    .package(url: "https://github.com/Shopify/mobile-buy-sdk-ios", from: "12.0.0")
]
```

Or in Xcode: **File** > **Add Package Dependencies** and enter `https://github.com/Shopify/mobile-buy-sdk-ios`.

***

## Step 4: Initialize the client

Create a client instance with your shop domain and Storefront API access token:

## Swift

```swift
import Buy


let client = Graph.Client(
    shopDomain: "{shop}.myshopify.com",
    apiKey: "{your_storefront_access_token}"
)
```

***

## Step 5: Fetch products

Query the Storefront API to get products. Save the variant ID for creating a cart:

## Swift

```swift
import Buy


func fetchProducts() {
    let query = Storefront.buildQuery { $0
        .products(first: 10) { $0
            .edges { $0
                .node { $0
                    .id()
                    .title()
                    .description()
                    .featuredImage { $0
                        .url()
                    }
                    .variants(first: 1) { $0
                        .edges { $0
                            .node { $0
                                .id()
                                .title()
                                .price { $0
                                    .amount()
                                    .currencyCode()
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    
    client.queryGraphWith(query) { result, error in
        if let products = result?.products.edges {
            for edge in products {
                let product = edge.node
                print("Product: \(product.title)")
            }
        }
    }
}
```

***

## Step 6: Create a cart

Use the variant ID to create a cart and get a `checkoutUrl`:

## Swift

```swift
import Buy


func createCart(variantId: GraphQL.ID) {
    let input = Storefront.CartInput.create(
        lines: .value([
            Storefront.CartLineInput.create(merchandiseId: variantId, quantity: .value(1))
        ])
    )
    
    let mutation = Storefront.buildMutation { $0
        .cartCreate(input: input) { $0
            .cart { $0
                .id()
                .checkoutUrl()  // Use this URL with Checkout Kit
            }
            .userErrors { $0
                .field()
                .message()
            }
        }
    }
    
    client.mutateGraphWith(mutation) { result, error in
        if let cart = result?.cartCreate?.cart {
            let checkoutUrl = cart.checkoutUrl
            // Pass this URL to Checkout Kit to present checkout
            print("Checkout URL: \(checkoutUrl)")
        }
    }
}
```

***

## Step 7: Present checkout with Checkout Kit

With the `checkoutUrl` from the cart, use [Checkout Kit](https://shopify.dev/docs/storefronts/mobile/checkout-kit) to present checkout:

## Swift

```swift
import ShopifyCheckoutSheetKit


func presentCheckout(checkoutUrl: URL) {
    ShopifyCheckoutSheetKit.present(checkout: checkoutUrl, from: self, delegate: self)
}
```

See [Embed Checkout Kit](https://shopify.dev/docs/storefronts/mobile/checkout-kit) for complete checkout setup.

***

## Configure universal links (optional)

Set up [universal links](https://developer.apple.com/ios/universal-links/) to integrate your app with Safari. When a buyer taps a link to your website, then your app opens if they have it installed.

**Note:**

Your online store automatically hosts the Apple app site association file at `/.well-known/apple-app-site-association`.

1. From your Shopify admin, go to [**Apps**](https://www.shopify.com/admin/apps).

1) Click **Develop apps**.
2) Click the name of your app.
3) Click **API Integrations**.
4) In the **Storefront API integration** section, click **Configure**.
5) Expand the **iOS Buy SDK configuration** section.
6) Enter your **Apple App ID**.
7) Select **Use iOS universal links**.

***

## Next steps

[Build a mobile storefront\
\
](https://shopify.dev/docs/storefronts/mobile/build-mobile-storefront?extension=swift)

[Build a complete shopping experience with products, cart, and checkout using the Storefront API and Checkout Kit.](https://shopify.dev/docs/storefronts/mobile/build-mobile-storefront?extension=swift)

[iOS Buy SDK on GitHub\
\
](https://github.com/Shopify/mobile-buy-sdk-ios)

[SDK source code and sample apps.](https://github.com/Shopify/mobile-buy-sdk-ios)

***

## Where to get help

Shopify support covers issues with the iOS Buy SDK itself, but not general mobile app development. Here's how to get help:

### [Hire a Shopify Partner](https://www.shopify.com/partners/directory)

Find a Shopify Partner for hire in our ecosystem of talented development agencies.

### [.dev Community](https://community.shopify.dev)

Ask questions and share knowledge with other Shopify developers.

### [Open a GitHub issue](https://github.com/Shopify/mobile-buy-sdk-ios/issues)

Report bugs or request features for the iOS Buy SDK.

***
