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

)observeValueForKeyPath 实现有问题 #3

Open
naniqingkuang opened this issue Nov 8, 2017 · 1 comment
Open

)observeValueForKeyPath 实现有问题 #3

naniqingkuang opened this issue Nov 8, 2017 · 1 comment

Comments

@naniqingkuang
Copy link

  • (BOOL)observeValueForKeyPath:(id)observer inkeySource:(id)keySource keyPath:(NSString*)path
    {
    NSString key = [NSString stringWithFormat:@"%@_%p",NSStringFromClass([observer class]),observer];
    [self.kvoMapLock lock];
    id obj = [self.kvoMap objectForKey:key];
    if ([obj isKindOfClass:[NSMutableArray class]]) {
    for (id source in obj) {
    if ([source isKindOfClass:[WTKVOResource class]]) {
    if ([(WTKVOResource
    )source resource] == nil && [(WTKVOResource*)source key] == path) {
    [obj removeObject:source];
    [self.kvoMapLock unlock];
    return YES;
    }
    }
    }
    }
    [self.kvoMapLock unlock];
    return NO;
    }

这个方法的实现有问题,在响应函数中删除监听的source,这个方法不应该重写,程序员要监听当然会实现这个方法,而没有这个方法,程序也不至于崩溃,望采纳

@hongruqi
Copy link
Owner

hongruqi commented Nov 8, 2017

@naniqingkuang 你说的对,这个时候不回导致crash,实现是多余的。

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

2 participants