Skip to content

Instantly share code, notes, and snippets.

@7gano
Last active September 27, 2015 05:47
Show Gist options
  • Save 7gano/1220899 to your computer and use it in GitHub Desktop.
Save 7gano/1220899 to your computer and use it in GitHub Desktop.
makeObjectsPerformSelector
#import <UIKit/UIKit.h>
int main(int argc, char *argv[])
{
@autoreleasepool {
UIView* superView = [[UIView alloc] initWithFrame:CGRectZero];
for(int i = 0; i < 10; i++){
UIView* view = [[UIView alloc] initWithFrame:CGRectZero];
[superView addSubview:view];
}
NSLog(@"count = %d", [superView.subviews count]);
[superView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
NSLog(@"count = %d", [superView.subviews count]);
}
}
2011-09-16 09:44:47.526 Hoge100[1529:40b] count = 10
2011-09-16 09:44:47.527 Hoge100[1529:40b] count = 0
makeObjectsPerformSelector:
Sends to each object in the array the message identified by a given selector,
starting with the first object and continuing through the array to the last object.
- (void)makeObjectsPerformSelector:(SEL)aSelector
Parameters
aSelector
A selector that identifies the message to send to the objects in the array.
The method must not take any arguments,
and must not have the side effect of modifying the receiving array.
Discussion
This method raises an NSInvalidArgumentException if aSelector is NULL.
Availability
Available in iOS 2.0 and later.
See Also
– makeObjectsPerformSelector:withObject:
Related Sample Code
LazyTableImages
Declared In
NSArray.h
@interface NSArray (NSExtendedArray)
- (void)makeObjectsPerformSelector:(SEL)aSelector;
- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)argument;
@interface NSSet (NSExtendedSet)
- (void)makeObjectsPerformSelector:(SEL)aSelector;
- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)argument;
@7gano
Copy link
Author

7gano commented Oct 3, 2013

それらを使うと、Rubyのmapっぽい感じになりますね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment