Closed thunderweasel closed 9 years ago
Hi Ryan, thanks for putting thought into this! I've been away from iOS development for a long time, and I've never used Storyboards. Can you outline how the awake method would be helpful?
I am not naturally inclined to reach for awake() methods, preferring instead to look to see if there's other ways to construct a scenario so that awake() is not needed.
I do think we should be practically-minded, and if there's a real need for awake() let's consider it. First it would help to understand the picture and to also hear from other Pivots. Presumably we've done a lot of projects with Storyboards and Blindside? How have those projects gotten along?
Our team in London has followed this example for using Blindside with Storyboards - perhaps you're familiar with it?
https://github.com/pivotal-brian-croom/BlindsidedStoryboard
Thanks!
On Fri, May 22, 2015 at 1:16 PM, pivotal-ryan-mcleod < notifications@github.com> wrote:
In places where the use of a BSPropertySet is unavoidable (for example, a view controller instantiated from a storyboard), it would be helpful if Blindside could call something like a "bsAwakeFromPropertyInjection" method on the object after the properties have been injected. It could be added to the category on NSObject.
I may do a pull request unless there is a compelling reason not to do this.
— Reply to this email directly or view it on GitHub https://github.com/jbsf/blindside/issues/22.
Yeah, BlindsidedStoryboard is usually what I and other Toronto pivots use in our projects for injecting into storyboards too. It's very handy, but all it does is call injectProperties: with the view controller after it's been instantiated by the storyboard. What usually trips up developers the most here is that this doesn't happen until after the view controller's awakeFromNib life cycle event. In truth, once you know this, it's not normally a big deal. You can usually move that same code into viewDidLoad instead. I don't think it's right that you should need to wait for your view to load before accessing your dependencies, but it usually doesn't make that much of a difference.
Where I more often wish this feature were present is when I'm injecting into views. Views don't have any other lifecycle events after awakeFromNib, so there's no natural entry point after property injection where I can perform setup that makes use of my injected properties. Usually what I do instead is add my own awake() method that has to be called in addition to injectProperties:, but I feel like it would be more natural if the Blindside framework handled this for me.
(I'm not sure if injecting into views is common among other pivots. I personally find it useful and appropriate from time to time, although I may be a deviant. Regardless, I think the problem has general applicability to any situation where you want to inject into an object that is constructed by a framework you don't have control over.)
I haven't really talked to a lot of other developers about this ask of mine, so I don't know yet if it's just me who would find this useful. There's a pretty large standup of iOS developers here at the Toronto office, so maybe I'll bring this up on Monday and find out if I'm just a crazy person.
So the results I got from iOS standup were sort of mixed. Some people thought it would be a useful feature, some people didn't really see the point. It didn't really seem like it was a huge pain point for other iOS developers, but I still personally think it would be a useful feature.
Brian Croom did point out that there was precedent for it, since Typhoon apparently has a similar method. Just because Typhoon does it, doesn't mean we should necessarily do it, but at least it's a sign that I'm not entirely off my rocker.
I'm not opposed to this, personally. I can see how it could fit logically into the BSLifecycle™, and people don't have to use it.
In your case, would -willMoveToSuperview help? Or does that feel dirty...?
Brian actually pointed out the possibility of willMoveToSuperview to me the other day. I honestly hadn't considered it, and it might kind of work as long as you don't need a 100% guarantee that your code won't be called more than once, but I still think it's dirty. I don't think we should have to be depending on lifecycle events from UIKit that have nothing to do with dependency injection just to delay long enough for our dependencies to be injected.
Where do we stand on this issue? Do we want to include it? I've talked to multiple people now who would like such a feature.
I'm tentatively +1 on this issue. In the SF office we occasionally struggle with storyboards and other ways of waking up an object without blindside. I can see how this would be a very useful feature.
Just my 2c.
Sent From A Very Small Keyboard
On Jun 17, 2015, at 08:14, pivotal-ryan-mcleod notifications@github.com wrote:
Where do we stand on this issue? Do we want to include it? I've talked to multiple people now who would like such a feature.
— Reply to this email directly or view it on GitHub.
While I feel strongly that putting code in a Blindside-specific method should be considered a last resort, I am still in favor of including it for those situations when hijacking other lifecycle methods just seems too wrong.
Thanks everyone! I think this is resolved.
In places where the use of a BSPropertySet is unavoidable (for example, a view controller instantiated from a storyboard), it would be helpful if Blindside could call something like a "bsAwakeFromPropertyInjection" method on the object after the properties have been injected. It could be added to the category on NSObject.
I may do a pull request unless there is a compelling reason not to do this.