下記のようにIn App Perpose用の`StoreObesrver`クラスを作成しました。

しかし、"EXC_BREAKPOINT"、"messaage sent to deallocated instance"のエラーがでてしまいます。  
原因はdelagate関連だと思っているのですが、解決方法が分かりません。

ご教示よろしくお願い致します

* * *

## error

xcode

[![enter image description
here](https://i.stack.imgur.com/OJYlk.png)](https://i.stack.imgur.com/OJYlk.png)

console

[![enter image description
here](https://i.stack.imgur.com/gyGzD.png)](https://i.stack.imgur.com/gyGzD.png)

* * *

## StoreObserver.swift

```

    public class StoreObserver: NSObject, UIAlertViewDelegate, SKPaymentTransactionObserver, SKProductsRequestDelegate {
    
        var productRequest:SKProductsRequest?
        var productIdentifiers = NSSet(objects: "com.xxx.xxx")
    
        override init() {
            super.init()
        }
    
        func canPayment() {
            if !SKPaymentQueue.canMakePayments() {
                showAlertView("Setting Error", message: "check your setting")
                return
            }
            productRequest = SKProductsRequest(productIdentifiers: productIdentifiers as Set<NSObject>)
            productRequest?.delegate = self
            productRequest?.start()
            }
    
        } // ここを出るとエラーがでます。
    
        public func productsRequest(request: SKRequest, didFailWithError error: NSError) {
            println("fail get")
        }
    
        public func productsRequest(request: SKProductsRequest!, didReceiveResponse response: SKProductsResponse!) {
            println("get item data")
         }
    
         func showAlertView(title:String,message:String){
            var alert = UIAlertView()
            alert.title = title
            alert.message = message
            alert.addButtonWithTitle("OK")
            alert.show()
        }
    
        deinit {
            productRequest?.delegate = nil
        }
    }
    
```
CC BY-SA 3.0
2015-08-22T08:49:30.713
14725
2015-08-22T09:51:06.307
2015-08-22T09:51:06.307
5337
11027
question
ios swift
自作クラスでEXC_BREAKPOINT messaage sent to deallocated instanceのエラー