{"action":"created","issue":{"url":"https://api.github.com/repos/groue/GRDB.swift/issues/351","repository_url":"https://api.github.com/repos/groue/GRDB.swift","labels_url":"https://api.github.com/repos/groue/GRDB.swift/issues/351/labels{/name}","comments_url":"https://api.github.com/repos/groue/GRDB.swift/issues/351/comments","events_url":"https://api.github.com/repos/groue/GRDB.swift/issues/351/events","html_url":"https://github.com/groue/GRDB.swift/pull/351","id":322597173,"number":351,"title":"Annotate `DatabaseQueue.write(_:)` with `@discardableResult`","user":{"login":"freak4pc","id":605076,"avatar_url":"https://avatars0.githubusercontent.com/u/605076?v=4","gravatar_id":"","url":"https://api.github.com/users/freak4pc","html_url":"https://github.com/freak4pc","followers_url":"https://api.github.com/users/freak4pc/followers","following_url":"https://api.github.com/users/freak4pc/following{/other_user}","gists_url":"https://api.github.com/users/freak4pc/gists{/gist_id}","starred_url":"https://api.github.com/users/freak4pc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freak4pc/subscriptions","organizations_url":"https://api.github.com/users/freak4pc/orgs","repos_url":"https://api.github.com/users/freak4pc/repos","events_url":"https://api.github.com/users/freak4pc/events{/privacy}","received_events_url":"https://api.github.com/users/freak4pc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-13T14:11:02Z","updated_at":"2018-05-15T10:39:14Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/groue/GRDB.swift/pulls/351","html_url":"https://github.com/groue/GRDB.swift/pull/351","diff_url":"https://github.com/groue/GRDB.swift/pull/351.diff","patch_url":"https://github.com/groue/GRDB.swift/pull/351.patch"},"body":"The returned result from `write(_:)` isn't necessarily needed, for example when just updating, or writing a new record in a database queue. \r\n\r\ne.g. \r\n\r\n```swift\r\ntry dbQueue.write { db in \r\n    try myModel.update(db)\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/groue/GRDB.swift/issues/comments/389122408","html_url":"https://github.com/groue/GRDB.swift/pull/351#issuecomment-389122408","issue_url":"https://api.github.com/repos/groue/GRDB.swift/issues/351","id":389122408,"user":{"login":"groue","id":54219,"avatar_url":"https://avatars2.githubusercontent.com/u/54219?v=4","gravatar_id":"","url":"https://api.github.com/users/groue","html_url":"https://github.com/groue","followers_url":"https://api.github.com/users/groue/followers","following_url":"https://api.github.com/users/groue/following{/other_user}","gists_url":"https://api.github.com/users/groue/gists{/gist_id}","starred_url":"https://api.github.com/users/groue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/groue/subscriptions","organizations_url":"https://api.github.com/users/groue/orgs","repos_url":"https://api.github.com/users/groue/repos","events_url":"https://api.github.com/users/groue/events{/privacy}","received_events_url":"https://api.github.com/users/groue/received_events","type":"User","site_admin":false},"created_at":"2018-05-15T10:39:14Z","updated_at":"2018-05-15T10:39:14Z","author_association":"OWNER","body":"Hello @freak4pc,\r\n\r\nI'm reluctant to accept this pull request. Look at the standard library behavior:\r\n\r\n```swift\r\nvar i = 1\r\n\r\n// no warning\r\nwithUnsafePointer(to: &i) { _ in\r\n    return ()\r\n}\r\n\r\n// warning: Result of call to 'withUnsafePointer(to:_:)' is unused\r\nwithUnsafePointer(to: &i) { _ in\r\n    return 1\r\n}\r\n```\r\n\r\n`withUnsafePointer` (and other stdlib methods that return the result of their closure argument) are not declared with the @discardableResult attribute. That would be dangerous.\r\n\r\nSwift is nice, and does not emit this warning when the closure returns Void, as in the 1st example above.\r\n\r\nI too wish that Swift were even nicer, and would not emit this warning for single-line closures that call a @discardableResult method. This should be pitched and discussed with core team and community on [Swift forums](http://forums.swift.org).\r\n\r\nBut the proper way to avoid this warning, in the current state of Swift, is to explicitly discard the value, as you would do with any other stdlib method:\r\n\r\n```swift\r\ntry dbQueue.write { db in\r\n    _ = try makeResultWithSideEffect()\r\n}\r\n```\r\n\r\nDid I miss something that should have GRDB chose another path?"}}
{"actor":{"display_login":"groue"}}