火星人驾到

iPhone object-c 的reflection使用方法

// Without reflection

  Foo *foo = [[Foo alloc] init];

  [foo hello];

  // With reflection

  Class cls = NSClassFromString(@"Foo");

  id foo = [[cls alloc] init];

  SEL selector = NSSelectorFromString(@"hello");

  [foo performSelector:selector withObject:nil];

posted on 2011-05-21 15:06  火星人驾到  阅读(194)  评论(0编辑  收藏  举报