nsomar / OAStackView

Porting UIStackView to iOS 7+
MIT License
2.14k stars 200 forks source link

NSMutableArray should not be declared as copy #65

Closed ZevEisenberg closed 8 years ago

ZevEisenberg commented 8 years ago

See here: https://github.com/oarrabi/OAStackView/blob/3569aad354210064de99a2f401ad9167fd358eba/Pod/Classes/OAStackView.m#L18

@property(nonatomic, copy) NSMutableArray *mutableArrangedSubviews;

In the code, this is only ever assigned via _mutableArrangedSubviews, so it doesn't cause problems. But if it is ever assigned via dot syntax, it will be assigned via a synthesized setter that looks something like this:

- (void)setMutableArrangedSubviews:(NSMutableArray *)mutableArrangedSubviews
{
    _mutableArrangedSubviews = [mutableArrangedSubviews copy];
}

_mutableArrangedSubviews is now of type NSArray, not NSMutableArray, and this code will crash if something tries to mutate it.

The fix:

@property(nonatomic, strong) NSMutableArray *mutableArrangedSubviews;
nsomar commented 8 years ago

I agree with your fix, can you please submit a PR with this fix?

nsomar commented 8 years ago

Sorry I didn't see the PR, I am viewing it now.