{"action":"created","issue":{"url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/122","labels_url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/122/labels{/name}","comments_url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/122/comments","events_url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/122/events","html_url":"https://github.com/ResearchKit/ResearchKit/issues/122","id":71447761,"number":122,"title":"taskViewController(_:shouldPresentStep:) crashes in Swift","user":{"login":"getaaron","id":789577,"avatar_url":"https://avatars.githubusercontent.com/u/789577?v=3","gravatar_id":"","url":"https://api.github.com/users/getaaron","html_url":"https://github.com/getaaron","followers_url":"https://api.github.com/users/getaaron/followers","following_url":"https://api.github.com/users/getaaron/following{/other_user}","gists_url":"https://api.github.com/users/getaaron/gists{/gist_id}","starred_url":"https://api.github.com/users/getaaron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getaaron/subscriptions","organizations_url":"https://api.github.com/users/getaaron/orgs","repos_url":"https://api.github.com/users/getaaron/repos","events_url":"https://api.github.com/users/getaaron/events{/privacy}","received_events_url":"https://api.github.com/users/getaaron/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-28T01:26:21Z","updated_at":"2015-04-28T05:53:56Z","closed_at":null,"body":"In this delegate method:\r\n\r\n    func taskViewController(taskViewController: ORKTaskViewController, shouldPresentStep step: ORKStep) -> Bool {\r\n        // use step\r\n    }\r\n\r\n`step` is guaranteed by the method signature to be non-nil, and crashes when using `step` if it's not. But this method has many code paths that can return `nil`:\r\n\r\n    - (ORKStep *)stepAfterStep:(ORKStep *)step withResult:(ORKTaskResult *)result {\r\n        NSArray *steps = _steps;\r\n        \r\n        if (steps.count <= 0) {\r\n            return nil;\r\n        }\r\n        \r\n        ORKStep *currentStep = step;\r\n        ORKStep *nextStep = nil;\r\n        \r\n        if (currentStep == nil) {\r\n            nextStep = steps[0];\r\n        } else {\r\n            NSUInteger index = [self indexOfStep:step];\r\n            \r\n            if (NSNotFound != index && index != (steps.count-1)) {\r\n                nextStep = steps[index+1];\r\n            }\r\n        }\r\n        return nextStep;\r\n    }\r\n\r\nOne possible workaround would be to wrap `[ORKTaskViewController -shouldPresentStep:]` in an `if (step) {…}`."},"comment":{"url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/comments/96924193","html_url":"https://github.com/ResearchKit/ResearchKit/issues/122#issuecomment-96924193","issue_url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/122","id":96924193,"user":{"login":"jwe-apple","id":11575859,"avatar_url":"https://avatars.githubusercontent.com/u/11575859?v=3","gravatar_id":"","url":"https://api.github.com/users/jwe-apple","html_url":"https://github.com/jwe-apple","followers_url":"https://api.github.com/users/jwe-apple/followers","following_url":"https://api.github.com/users/jwe-apple/following{/other_user}","gists_url":"https://api.github.com/users/jwe-apple/gists{/gist_id}","starred_url":"https://api.github.com/users/jwe-apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwe-apple/subscriptions","organizations_url":"https://api.github.com/users/jwe-apple/orgs","repos_url":"https://api.github.com/users/jwe-apple/repos","events_url":"https://api.github.com/users/jwe-apple/events{/privacy}","received_events_url":"https://api.github.com/users/jwe-apple/received_events","type":"User","site_admin":false},"created_at":"2015-04-28T05:53:56Z","updated_at":"2015-04-28T05:53:56Z","body":"Agree, that's the correct fix. `stepAfterStep:withResult:` is correctly annotated as nullable input and nullable result. `shouldPresentStep:` should not be called with a nil `step`."}}