我是靠谱客的博主 妩媚御姐,最近开发中收集的这篇文章主要介绍NSEnumerator,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

在阅读第三方类MBProgressHUD时,看到这样的一个函数,NSEnumerator平常用的很少。

+ (MB_INSTANCETYPE)HUDForView:(UIView *)view {
	NSEnumerator *subviewsEnum = [view.subviews reverseObjectEnumerator];
	for (UIView *subview in subviewsEnum) {
		if ([subview isKindOfClass:self]) {
			return (MBProgressHUD *)subview;
		}
	}
	return nil;
}
NSEnumerator是一个抽象类,集合类(如:NSArray、NSSet、NSDictionary等)均可获取到NSEnumerator,常用来遍历数组或者字典等。比如

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                         [[Photo alloc] init], @"p1",
                         [[Photo alloc] init], @"p2",
                         [[Photo alloc] init], @"p3", nil];
     
    //allValues 只能获取字典中值的数组列表,注意列表是无序的。
    NSEnumerator *myEnumerator = [[dict allValues] objectEnumerator];
     
    Photo *photo;
    while((photo = [myEnumerator nextObject]))
    {
        [photo draw];
    }


最后

以上就是妩媚御姐为你收集整理的NSEnumerator的全部内容,希望文章能够帮你解决NSEnumerator所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(108)

评论列表共有 0 条评论

立即
投稿
返回
顶部