Skip to content

Instantly share code, notes, and snippets.

@jazzychad
Created August 12, 2014 20:22
Show Gist options
  • Save jazzychad/80d175951ffba5218940 to your computer and use it in GitHub Desktop.
Save jazzychad/80d175951ffba5218940 to your computer and use it in GitHub Desktop.
Snippet for UIViews which visually represent an object
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)layoutSubviews
{
[super layoutSubviews];
}
- (void)_updateUIFor<#Property#>
{
}
- (void)set<#Property#>:(<#class#> *)<#parameter#>
{
if (<#ivar#> != <#parameter#>) {
if (<#ivar#>) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:<#NotifName#> object:<#ivar#>];
}
<#ivar#> = <#parameter#>;
if (<#ivar#>) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(<#ivar#>DidUpdate:) name:<#NotifName#> object:<#ivar#>];
}
[self _updateUIFor<#Property#>];
}
}
- (void)<#ivar#>DidUpdate:(NSNotification *)note
{
[self _updateUIFor<#Property#>];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment