All Downloads are FREE. Search and download functionalities are using the official Maven repository.

objc.Object-body.mustache Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
#import "{{classPrefix}}Object.h"

@implementation {{classPrefix}}Object

/**
 * Workaround for JSONModel multithreading issues
 * https://github.com/icanzilb/JSONModel/issues/441
 */
- (instancetype)initWithDictionary:(NSDictionary *)dict error:(NSError **)err {
    static NSMutableSet *classNames;
    static NSObject *lock;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        classNames = [NSMutableSet new];
        lock = [NSObject new];
    });

    BOOL initSync;
    @synchronized(lock)
    {
        NSString *className = NSStringFromClass([self class]);
        initSync = ![classNames containsObject:className];
        if(initSync)
        {
            [classNames addObject:className];
            self = [super initWithDictionary:dict error:err];
        }
    }
    if(!initSync)
    {
        self = [super initWithDictionary:dict error:err];
    }
    return self;
}

/**
 * Gets the string presentation of the object.
 * This method will be called when logging model object using `NSLog`.
 */
- (NSString *)description {
    return [[self toDictionary] description];
}

@end




© 2015 - 2024 Weber Informatics LLC | Privacy Policy