         override func string(forKey defaultName: String) -> String? {
             return appUserID
         }
+
+        override func set(_ value: Any?, forKey defaultName: String) {
+            appUserID = value as! String?
+        }
     }
 
     class PurchasesDelegate: RCPurchasesDelegate {

    var purchases: RCPurchases?

    func setupPurchases() {
        purchases = RCPurchases.init(appUserID: appUserID,
                                     requestFetcher: requestFetcher,
                                     backend:backend,
                                     storeKitWrapper: storeKitWrapper,
                                     notificationCenter:notificationCenter,
                                     userDefaults:userDefaults)

        purchases!.delegate = purchasesDelegate
    }

    func setupAnonPurchases() {
        purchases = RCPurchases.init(appUserID: nil,
                                     requestFetcher: requestFetcher,
                                     backend:backend,
                                     storeKitWrapper: storeKitWrapper,
                                     notificationCenter:notificationCenter,
                                     userDefaults:userDefaults)

        purchases!.delegate = purchasesDelegate
    }

        expect(purchaserInfo).toEventuallyNot(beNil());
    }

    func testAnonPurchasesGeneratesAnAppUserID() {
        setupAnonPurchases()
        expect(self.purchases?.appUserID).toNot(beEmpty())
    }

    func testAnonPurchasesSavesTheAppUserID() {
        setupAnonPurchases()
        expect(self.userDefaults.appUserID).toNot(beNil())
    }

    func testAnonPurchasesReadsSavedAppUserID() {
        let appUserID = "jerry"
        userDefaults.appUserID = appUserID
        setupAnonPurchases()

        expect(self.purchases?.appUserID).to(equal(appUserID))
    }
}
