Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'NSInvalidArgumentException', reason: '*** -propertyForKey: only defined for abstract class #250

Open
konomae opened this issue Aug 30, 2017 · 1 comment · May be fixed by #262
Open

'NSInvalidArgumentException', reason: '*** -propertyForKey: only defined for abstract class #250

konomae opened this issue Aug 30, 2017 · 1 comment · May be fixed by #262

Comments

@konomae
Copy link

konomae commented Aug 30, 2017

Hi

I found this exception in Crashlytics crash logs from my production app.
I can reproduce and paste it bellow. But I cannot find how to fix it.
So, I just report this.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -propertyForKey: only defined for abstract class.  Define -[_TtCV6APIKit31MultipartFormDataBodyParameters20MultipartInputStream propertyForKey:]!'
  • Xcode 8.3.3
  • iOS 10.3 SDK
  • iPhone Plus (iOS 10.3 simulator)
import UIKit
import APIKit

protocol HttpBinRequest: Request {

}

extension HttpBinRequest {
    var baseURL: URL {
        return URL(string: "https://httpbin.org")!
    }
}

struct PostRequest: HttpBinRequest {
    typealias Response = Any

    var method: HTTPMethod {
        return .post
    }

    var path: String {
        return "/post"
    }

    var bodyParameters: BodyParameters? {
        let p = try! MultipartFormDataBodyParameters.Part(
            value: "value",
            name: "name"
        )

        return MultipartFormDataBodyParameters(parts: [p], entityType: .inputStream)
    }

    func response(from object: Any, urlResponse: HTTPURLResponse) throws -> Response {
        return object
    }
}

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let request = PostRequest()

        Session.send(request) { result in
            print(result)
            switch result {
            case .success(let response):
                print(response)
            case .failure(let error):
                print("error: \(error)")
            }
        }
    }
}
@konomae
Copy link
Author

konomae commented Aug 17, 2018

Minimize test case

func testReproduceIssue250() {
    struct PostRequest: Request {
        let baseURL = URL(string: "https://httpbin.org")!
        let method: HTTPMethod = .post
        let path = "/post"
        let bodyParameters: BodyParameters? = MultipartFormDataBodyParameters(
            parts: [],
            entityType: .inputStream
        )

        func response(from object: Any, urlResponse: HTTPURLResponse) throws -> Any {
            return object
        }
    }

    let expectation = self.expectation(description: #function)
    let request = PostRequest()
    Session.send(request) { result in
        switch result {
        case .success:
            expectation.fulfill()
        case .failure:
            XCTFail()
        }
    }

    wait(for: [expectation], timeout: 3.0)
}
'NSInvalidArgumentException', reason: '*** -propertyForKey: only defined for abstract class.  Define -[_TtCV6APIKit31MultipartFormDataBodyParameters20MultipartInputStream propertyForKey:]!'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant