Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save pwblaine/074eee3e8ccfd5b93e09 to your computer and use it in GitHub Desktop.

Select an option

Save pwblaine/074eee3e8ccfd5b93e09 to your computer and use it in GitHub Desktop.

Revisions

  1. @kostiakoval kostiakoval revised this gist Mar 30, 2014. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  2. @kostiakoval kostiakoval revised this gist Mar 29, 2014. 1 changed file with 26 additions and 0 deletions.
    26 changes: 26 additions & 0 deletions KKExample.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    //
    // NSObject+Assosiated.h
    // NSObject-Associated
    //
    // Created by Konstantin Koval on 29/03/14.
    // Copyright (c) 2014 Konstantin Koval. All rights reserved.
    //

    #import <Foundation/Foundation.h>

    @interface NSObject (AssociatedTest)

    @property (nonatomic, strong) NSString *name;
    @property (nonatomic, assign) id delegate;

    @end

    // Implementation
    #import "KKNSObject+Associated.h"

    @implementation NSObject (AssociatedTest)

    ASSOCIATED(name, setName, NSString *, OBJC_ASSOCIATION_RETAIN_NONATOMIC)
    ASSOCIATED(delegate, setDelegate, id, OBJC_ASSOCIATION_ASSIGN)

    @end
  3. @kostiakoval kostiakoval revised this gist Mar 29, 2014. 2 changed files with 5 additions and 5 deletions.
    6 changes: 3 additions & 3 deletions Associated
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    - (<#type#>)<#propertyName#> {
    return [objc_getAssociatedObject(self, _cmd) <#NSNumberMethod#>];
    return objc_getAssociatedObject(self, _cmd);
    }

    - (void)set<#propertyName#>:(<#type#>)object
    {
    objc_setAssociatedObject(self, @selector(<#propertyName#>), [NSNumber numberWith:object], OBJC_ASSOCIATION_);
    }
    objc_setAssociatedObject(self, @selector(<#propertyName#>), object, OBJC_ASSOCIATION_);
    }
    4 changes: 2 additions & 2 deletions Associated-Objects → Associated-NSNumber
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    - (<#type#>)<#propertyName#> {
    return objc_getAssociatedObject(self, _cmd);
    return [objc_getAssociatedObject(self, _cmd) <#NSNumberMethod#>];
    }

    - (void)set<#propertyName#>:(<#type#>)object
    {
    objc_setAssociatedObject(self, @selector(<#propertyName#>), object, OBJC_ASSOCIATION_);
    objc_setAssociatedObject(self, @selector(<#propertyName#>), [NSNumber numberWith:object], OBJC_ASSOCIATION_);
    }
  4. @kostiakoval kostiakoval renamed this gist Mar 29, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @kostiakoval kostiakoval revised this gist Mar 29, 2014. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  6. @kostiakoval kostiakoval revised this gist Mar 29, 2014. 3 changed files with 36 additions and 1 deletion.
    8 changes: 8 additions & 0 deletions Associated Objects
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    - (<#type#>)<#propertyName#> {
    return objc_getAssociatedObject(self, _cmd);
    }

    - (void)set<#propertyName#>:(<#type#>)object
    {
    objc_setAssociatedObject(self, @selector(<#propertyName#>), object, OBJC_ASSOCIATION_);
    }
    1 change: 0 additions & 1 deletion new_gist_file_0 → Associated primitive
    Original file line number Diff line number Diff line change
    @@ -6,4 +6,3 @@
    {
    objc_setAssociatedObject(self, @selector(<#propertyName#>), [NSNumber numberWith:object], OBJC_ASSOCIATION_);
    }

    28 changes: 28 additions & 0 deletions KKNSObject+Associated.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    //
    // KKNSObject+Assosiated.h
    // NSObject-Associated
    //
    // Created by Konstantin Koval on 29/03/14.
    // Copyright (c) 2014 Konstantin Koval. All rights reserved.
    //

    /**
    * A macro that creates getter and setter for your assosiated object
    *
    * @param propertyName Getter funtion name
    * @param setter Setter funtion name
    * @param objc_AssociationPolicy Memory policy for assosiated object
    *
    * Available option: OBJC_ASSOCIATION_ASSIGN, OBJC_ASSOCIATION_RETAIN_NONATOMIC, OBJC_ASSOCIATION_COPY_NONATOMIC, OBJC_ASSOCIATION_RETAIN, OBJC_ASSOCIATION_COPY
    *
    */
    #import <objc/runtime.h>
    #define ASSOCIATED(propertyName, setter, type, objc_AssociationPolicy)\
    - (type)propertyName {\
    return objc_getAssociatedObject(self, _cmd);\
    }\
    \
    - (void)setter:(type)object\
    {\
    objc_setAssociatedObject(self, @selector(propertyName), object, objc_AssociationPolicy);\
    }
  7. @kostiakoval kostiakoval revised this gist Mar 29, 2014. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion new_gist_file_0
    Original file line number Diff line number Diff line change
    @@ -1 +1,9 @@
    _
    - (<#type#>)<#propertyName#> {
    return [objc_getAssociatedObject(self, _cmd) <#NSNumberMethod#>];
    }

    - (void)set<#propertyName#>:(<#type#>)object
    {
    objc_setAssociatedObject(self, @selector(<#propertyName#>), [NSNumber numberWith:object], OBJC_ASSOCIATION_);
    }

  8. @kostiakoval kostiakoval created this gist Mar 29, 2014.
    1 change: 1 addition & 0 deletions new_gist_file_0
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    _