Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不能用一个NSMapTable管理吗? #8

Open
qqzhao opened this issue Dec 23, 2016 · 0 comments
Open

不能用一个NSMapTable管理吗? #8

qqzhao opened this issue Dec 23, 2016 · 0 comments

Comments

@qqzhao
Copy link

qqzhao commented Dec 23, 2016

- (void)py_addToThemeColorPool:(NSString *)propertyName
{
    // 如果对象为_UIAppearance,直接返回
    Class appearanceClass = NSClassFromString(@"_UIAppearance");
    if ([self isMemberOfClass:appearanceClass]) return;
    // 键:对象地址+属性名 值:对象
    NSString *pointString = [NSString stringWithFormat:@"%p%@", self, propertyName];
    // 采用NSMapTable存储对象,使用弱引用
    NSMapTable *mapTable = [NSMapTable mapTableWithKeyOptions:NSMapTableCopyIn valueOptions:NSMapTableWeakMemory];
    [mapTable setObject:self forKey:pointString];
    // 判断是否已经在主题色中
    if (![[self themeColorPool] containsObject:mapTable]) { // 不在主题色池中
        [[self themeColorPool] addObject:mapTable];
        if (_currentThemeColor) { // 已经设置主题色,直接设置
            [self setValue:_currentThemeColor forKey:propertyName];
        }
    }
}

这里面的mapTable每次都是新创建的吧,不需要判断吧?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant