{"action":"created","issue":{"url":"https://api.github.com/repos/nickoneill/PermissionScope/issues/79","labels_url":"https://api.github.com/repos/nickoneill/PermissionScope/issues/79/labels{/name}","comments_url":"https://api.github.com/repos/nickoneill/PermissionScope/issues/79/comments","events_url":"https://api.github.com/repos/nickoneill/PermissionScope/issues/79/events","html_url":"https://github.com/nickoneill/PermissionScope/issues/79","id":103808872,"number":79,"title":"Refactoring","user":{"login":"bre7","id":3183848,"avatar_url":"https://avatars.githubusercontent.com/u/3183848?v=3","gravatar_id":"","url":"https://api.github.com/users/bre7","html_url":"https://github.com/bre7","followers_url":"https://api.github.com/users/bre7/followers","following_url":"https://api.github.com/users/bre7/following{/other_user}","gists_url":"https://api.github.com/users/bre7/gists{/gist_id}","starred_url":"https://api.github.com/users/bre7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bre7/subscriptions","organizations_url":"https://api.github.com/users/bre7/orgs","repos_url":"https://api.github.com/users/bre7/repos","events_url":"https://api.github.com/users/bre7/events{/privacy}","received_events_url":"https://api.github.com/users/bre7/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nickoneill/PermissionScope/labels/enhancement","name":"enhancement","color":"5319e7"},{"url":"https://api.github.com/repos/nickoneill/PermissionScope/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-28T22:59:15Z","updated_at":"2015-08-29T00:02:56Z","closed_at":null,"body":"* Move status/request methods to each PermissionConfig\r\n * Not possible to add them to the protocol. E.g: HealthKit requires parameters"},"comment":{"url":"https://api.github.com/repos/nickoneill/PermissionScope/issues/comments/135918277","html_url":"https://github.com/nickoneill/PermissionScope/issues/79#issuecomment-135918277","issue_url":"https://api.github.com/repos/nickoneill/PermissionScope/issues/79","id":135918277,"user":{"login":"bre7","id":3183848,"avatar_url":"https://avatars.githubusercontent.com/u/3183848?v=3","gravatar_id":"","url":"https://api.github.com/users/bre7","html_url":"https://github.com/bre7","followers_url":"https://api.github.com/users/bre7/followers","following_url":"https://api.github.com/users/bre7/following{/other_user}","gists_url":"https://api.github.com/users/bre7/gists{/gist_id}","starred_url":"https://api.github.com/users/bre7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bre7/subscriptions","organizations_url":"https://api.github.com/users/bre7/orgs","repos_url":"https://api.github.com/users/bre7/repos","events_url":"https://api.github.com/users/bre7/events{/privacy}","received_events_url":"https://api.github.com/users/bre7/received_events","type":"User","site_admin":false},"created_at":"2015-08-29T00:02:56Z","updated_at":"2015-08-29T00:02:56Z","body":"How to refactor the request methods to each Permission ?\r\n\r\nSolution 1: `request()` has closure parameters for each status\r\n```swift\r\npublic func request(closure1, closure2, closure3) {\r\n        switch status() {\r\n        case .Unknown:\r\n            /// some code\r\n           closure1()\r\n        case .Unauthorized:\r\n           closure2()\r\n        case .Disabled:\r\n           closure3()\r\n        case .Authorized:\r\n            break\r\n        }\r\n    }\r\n```\r\nA bit messy ?\r\n\r\nSolution 2: Use one closure\r\n```swift\r\npublic func request(closure1) {\r\n       let currentStatus = status()\r\n        switch currentStatus {\r\n        case .Unknown:\r\n            /// some code\r\n           closure1(currentStatus)\r\n        default:\r\n            closure1(currentStatus)\r\n        }\r\n    }\r\n```\r\nPermissionScope will usually ignore .Authorized status and show alerts for the other cases."}}