zoukankan      html  css  js  c++  java
  • 隐式循环

    定义一个Photo类,并带有2个draw方法, 一个带参数、一个不带参数。
    Photo.h
    #import <Foundation/Foundation.h>
    
    @interface Photo : NSObject {
    @private
       
    }
    
    -(void) draw;
    -(void) draw:(NSNumber*) number;
    
    @end
    
    Photo.m
    #import "Photo.h"
    
    @implementation Photo
    
    
    - (id)init
    {
        self = [super init];
        if (self) {
            // Initialization code here.
        }
        
        return self;
    }
    
    - (void)dealloc
    {
        [super dealloc];
    }
    
    -(void) draw
    {
        [self draw:[NSNumber numberWithInt:(arc4random() % 100)]];
    
    }
    
    -(void) draw:(NSNumber *)number
    {
        NSLog(@"%@", number);
    }
    
    @end
    
    main.m
    #import <Foundation/Foundation.h>
    #import "Photo.h"
    
    int main (int argc, const char * argv[])
    {
    
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
        //创建Photo数组
        NSArray *photos = [NSArray arrayWithObjects:[[Photo alloc] init],[[Photo alloc] init], nil];
        
        //不带参数
        [photos makeObjectsPerformSelector:@selector(draw)];//这里不用有:,是因为没有参数
        
        //带参数
        [photos makeObjectsPerformSelector:@selector(draw:) withObject:[NSNumber numberWithInt:(arc4random() % 101 +100)]];
        
        [pool drain];
        return 0;
    }
    
    结果:
    [Switching to process 4348 thread 0x0]
    2011-05-10 10:34:23.036 demo01[4348:903] 85
    2011-05-10 10:34:23.039 demo01[4348:903] 33
    2011-05-10 10:34:23.040 demo01[4348:903] 153
    2011-05-10 10:34:23.040 demo01[4348:903] 153
    
  • 相关阅读:
    第一阶段冲刺05
    生成器
    三元表达式 ,列表推导式 , 字典生成式
    装饰器
    闭包函数
    函数的定义和参数
    列表内置方法
    字符串的内置方法
    py_11_ 0731
    py_11_ 0730
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/2041895.html
Copyright © 2011-2022 走看看