{"action":"created","issue":{"url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/343","labels_url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/343/labels{/name}","comments_url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/343/comments","events_url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/343/events","html_url":"https://github.com/ResearchKit/ResearchKit/pull/343","id":98242874,"number":343,"title":"Constraint code homogenization","user":{"login":"rsanchezsaez","id":444313,"avatar_url":"https://avatars.githubusercontent.com/u/444313?v=3","gravatar_id":"","url":"https://api.github.com/users/rsanchezsaez","html_url":"https://github.com/rsanchezsaez","followers_url":"https://api.github.com/users/rsanchezsaez/followers","following_url":"https://api.github.com/users/rsanchezsaez/following{/other_user}","gists_url":"https://api.github.com/users/rsanchezsaez/gists{/gist_id}","starred_url":"https://api.github.com/users/rsanchezsaez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsanchezsaez/subscriptions","organizations_url":"https://api.github.com/users/rsanchezsaez/orgs","repos_url":"https://api.github.com/users/rsanchezsaez/repos","events_url":"https://api.github.com/users/rsanchezsaez/events{/privacy}","received_events_url":"https://api.github.com/users/rsanchezsaez/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":18,"created_at":"2015-07-30T19:22:53Z","updated_at":"2015-09-23T19:27:30Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ResearchKit/ResearchKit/pulls/343","html_url":"https://github.com/ResearchKit/ResearchKit/pull/343","diff_url":"https://github.com/ResearchKit/ResearchKit/pull/343.diff","patch_url":"https://github.com/ResearchKit/ResearchKit/pull/343.patch"},"body":"I went over all classes with constraints and homogenized the constraint code (this is a big pull request). This partially deals with [Issue #110](https://github.com/ResearchKit/ResearchKit/issues/110), and is related to the comments in [Issue #99](https://github.com/ResearchKit/ResearchKit/issues/99).\r\n\r\nWhile I was doing this, I tested every individual class immediately after changing it. I tried not to break anything, but a full UI review would be a good idea.\r\n\r\nIt takes care of the following items (some are purely stylistic, but others slightly affect how the code works):\r\n\r\n*Stylistic changes*\r\n- Always use the property format when doing `view.translatesAutoresizingMaskIntoConstraints = NO` instead of the method format (`setTranslatesAutoresizingMaskIntoConstraints:`).\r\n- Align all constraint code so it doesn't overflow the screen (easier to read).\r\n- Use `CGFloat` literals (`1.0` and `0.0`) on `multiplier` and `constant` parameters when creating constraints. This visually indicates that these are `CGFloat`.\r\n- Use the `ORKScreenMetricMaxDimension` constant instead of magic numbers for constraints requesting a very large width or height.\r\n- Use `(NSLayoutFormatOptions)0` instead of just `0` when passing constraint options (makes argument clearer).\r\n- Use `[array count]` method syntax instead of `array.count` property syntax.\r\n\r\n*Code changes*\r\n- All constraints are added and removed by activation/deactivation (`NSLayoutConstraint activateConstraints:` and `NSLayoutConstraint deactivateConstraints`). This is the [preferred way of doing it on *iOS 8* and up](https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/#//apple_ref/occ/instp/NSLayoutConstraint/active) as it adds the constraints at the most optimal place.\r\n- Make sure static constraints are created only once, usually in the `-setUpConstraints` method.\r\n- Variable constraints (which need to be recalculated) are always stored in the `_variableConstraints` ivar. These are always removed and recreated in the same way.\r\n- Constraints which need *constant* updating are stored as ivars (instead of in a `NSDictionary`): less boilerplatery and more type-safe.\r\n- Constraints which need *constant* updating are updated on the `updateConstraintsConstantForWindow:` method. This method is usually called: when there are changes in the view; in `-updateConstraints`; and in `-willMoveToWindow:`. The last one is the reason of the window argument.\r\n- Remove all `_screenType` ivars, which was needless artificial state (error prone). Instead, the constraints are updated correctly by passing the appropriate `UIWindow` to `updateConstraintsConstantForWindow:`.\r\n- `ORKImageSelectionView` structure was simplified by dropping the invisible label (the choice label takes the functionality of making sure the `intrinsicContentSize` is tall enough for the tallest string choice).\r\n- Use internal *ivars* instead of internal properties in some classes (for coherence with most of the code).\r\n\r\nI may be forgetting other things that I did, I'll update the PR if something comes up. Let me know if you have any question.\r\n\r\nAlthough these changes will be quite a task to review, I think they make constraint code more homogenous, more stable, easier to read, and easier to maintain."},"comment":{"url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/comments/142704509","html_url":"https://github.com/ResearchKit/ResearchKit/pull/343#issuecomment-142704509","issue_url":"https://api.github.com/repos/ResearchKit/ResearchKit/issues/343","id":142704509,"user":{"login":"rsanchezsaez","id":444313,"avatar_url":"https://avatars.githubusercontent.com/u/444313?v=3","gravatar_id":"","url":"https://api.github.com/users/rsanchezsaez","html_url":"https://github.com/rsanchezsaez","followers_url":"https://api.github.com/users/rsanchezsaez/followers","following_url":"https://api.github.com/users/rsanchezsaez/following{/other_user}","gists_url":"https://api.github.com/users/rsanchezsaez/gists{/gist_id}","starred_url":"https://api.github.com/users/rsanchezsaez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsanchezsaez/subscriptions","organizations_url":"https://api.github.com/users/rsanchezsaez/orgs","repos_url":"https://api.github.com/users/rsanchezsaez/repos","events_url":"https://api.github.com/users/rsanchezsaez/events{/privacy}","received_events_url":"https://api.github.com/users/rsanchezsaez/received_events","type":"User","site_admin":false},"created_at":"2015-09-23T19:27:30Z","updated_at":"2015-09-23T19:27:30Z","body":"Yeah, that's an unrelated problem. I have submitted a separate [PR](https://github.com/ResearchKit/ResearchKit/issues/474) with a fix."}}