技术的乐趣在于分享,欢迎多多交流,多多沟通。
全部博文(877)
分类: iOS平台
2015-09-22 17:12:41
//
// main.m
// command
//
// Created by Admin on 9/22/15.
// Copyright (c) 2015 5. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Animal.h"
@interface myClass : NSObject
- (void)timeLoop:(NSTimer *)timer;
@end
@implementation myClass
- (void)timeLoop:(NSTimer *)timer
{
NSLog(@"this is .....");
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
Animal *dog = [[Animal alloc] init];
myClass *m = [[myClass alloc] init];
[NSTimer scheduledTimerWithTimeInterval:2.0 target:m selector:@selector(timeLoop:) userInfo:nil repeats:YES];
while (1) {
[[NSRunLoop currentRunLoop] run];
}
//NSLog(<#NSString *format, ...#>)
}
return 0;
}
#import <Foundation/Foundation.h>
typedef int(^MyBlock) (int);
@interface Person : NSObject
- (void)show;
@property(nonatomic, copy)NSString *name;
@property(nonatomic, strong)MyBlock myblock;
@end
#import "Person.h"
@interface Person ()
@end
@implementation Person
- (instancetype)init
{
self = [super init];
if (self) {
//[self show];
}
return self;
}
- (void)show
{
_myblock(20);
}
@end
#import <Foundation/Foundation.h>
@interface Animal : NSObject
@property(nonatomic, assign)NSUInteger type;
@end
#import "Animal.h"
#import "Person.h"
@implementation Animal
- (instancetype)init
{
self = [super init];
if (self) {
Person *xiaoming = [[Person alloc] init];
xiaoming.myblock = ^(int a){
NSLog(@"the block num is %d", a);
return a;
};
[xiaoming show];
}
return self;
}
@end