{"action":"created","issue":{"url":"https://api.github.com/repos/smileyborg/PureLayout/issues/68","labels_url":"https://api.github.com/repos/smileyborg/PureLayout/issues/68/labels{/name}","comments_url":"https://api.github.com/repos/smileyborg/PureLayout/issues/68/comments","events_url":"https://api.github.com/repos/smileyborg/PureLayout/issues/68/events","html_url":"https://github.com/smileyborg/PureLayout/pull/68","id":84792715,"number":68,"title":"Allow a single view to be automatically distributed","user":{"login":"pnc","id":108524,"avatar_url":"https://avatars.githubusercontent.com/u/108524?v=3","gravatar_id":"","url":"https://api.github.com/users/pnc","html_url":"https://github.com/pnc","followers_url":"https://api.github.com/users/pnc/followers","following_url":"https://api.github.com/users/pnc/following{/other_user}","gists_url":"https://api.github.com/users/pnc/gists{/gist_id}","starred_url":"https://api.github.com/users/pnc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnc/subscriptions","organizations_url":"https://api.github.com/users/pnc/orgs","repos_url":"https://api.github.com/users/pnc/repos","events_url":"https://api.github.com/users/pnc/events{/privacy}","received_events_url":"https://api.github.com/users/pnc/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-06-03T22:08:10Z","updated_at":"2015-07-05T23:36:10Z","closed_at":"2015-07-05T23:20:11Z","pull_request":{"url":"https://api.github.com/repos/smileyborg/PureLayout/pulls/68","html_url":"https://github.com/smileyborg/PureLayout/pull/68","diff_url":"https://github.com/smileyborg/PureLayout/pull/68.diff","patch_url":"https://github.com/smileyborg/PureLayout/pull/68.patch"},"body":"`NSArray`'s `autoDistributeViewsAlongAxis:` requires 2 views, but the code works perfectly with just a single subview! Since the `NSAssert` is from the initial commit, I thought perhaps this had been an early sanity check and not a specific design decision.\r\n\r\nI think it might make more sense to only require a single view (or perhaps none at all, in which case the method might no-op, monad-style) so that callers don't have to check the number of items in the array and implement different functionality in the case of a single view.\r\n\r\nI'd be happy to add a test for the new single-view case if you're open to this patch.\r\n\r\nOne use case is a view with a small but variable number of children, such as a toolbar of buttons."},"comment":{"url":"https://api.github.com/repos/smileyborg/PureLayout/issues/comments/118676813","html_url":"https://github.com/smileyborg/PureLayout/pull/68#issuecomment-118676813","issue_url":"https://api.github.com/repos/smileyborg/PureLayout/issues/68","id":118676813,"user":{"login":"smileyborg","id":1372557,"avatar_url":"https://avatars.githubusercontent.com/u/1372557?v=3","gravatar_id":"","url":"https://api.github.com/users/smileyborg","html_url":"https://github.com/smileyborg","followers_url":"https://api.github.com/users/smileyborg/followers","following_url":"https://api.github.com/users/smileyborg/following{/other_user}","gists_url":"https://api.github.com/users/smileyborg/gists{/gist_id}","starred_url":"https://api.github.com/users/smileyborg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smileyborg/subscriptions","organizations_url":"https://api.github.com/users/smileyborg/orgs","repos_url":"https://api.github.com/users/smileyborg/repos","events_url":"https://api.github.com/users/smileyborg/events{/privacy}","received_events_url":"https://api.github.com/users/smileyborg/received_events","type":"User","site_admin":false},"created_at":"2015-07-05T23:36:10Z","updated_at":"2015-07-05T23:36:10Z","body":"OK, reviewed the changes and looks great! Just committed them to master. Thanks again for taking the time to submit this!\r\n\r\nNow, just in case you're interested, regarding this: \r\n> To that end, the only thing I had to change to get the existing implementations to work with a single view was a tweak to how `al_commonSuperviewOfViews` handles the single-view case. Although there was a test case checking that the \"common superview\" of a single view was that view itself, this isn't consistent with how al_commonSuperviewOfViews is used—the only call site (in the autoDistributeViewsAlongAxis…withFixedSize implementation) expects it to always return a containing superview of the views in the list, which it now does.\r\n\r\nThe reason you had to make that slight change in behavior to `al_commonSuperviewOfViews` is because the original goal of that method was to return the appropriate view where we could add the necessary constraints. And if you only have 1 view involved in a constraint, you are allowed to add that constraints to itself. Now, this method isn't being used for this purpose anymore -- it's just used for distributing views -- so the new behavior actually makes more sense. (Moreover, we no longer need to identify the right view to add constraints to; we just activate and deactivate them and let Apple deal with it.) Just in case you were wondering about this.\r\n\r\nFinally, regarding allowing the 0 view use case, I've been thinking about it and actually changed my mind here. The 1-view case is definitely great to support, but I think the 0-view case is a little murkier, especially in Objective-C where it's very easy to have `nil` sneak up on you. The real-world 0-view use case seems relatively unlikely, especially compared to the likelihood of some sort of bug causing your view array to be empty when you didn't want or expect that. Given this, I think keeping in the debug assert is beneficial in order to hopefully help catch a real issue early on, instead of \"silently failing\". (And technically, even the current code should support 0 views without crashing in a Release build when asserts are compiled out.) Do you agree?"}}