省市县用对象实现

来源:互联网 发布:seo按天付费 编辑:程序博客网 时间:2024/04/28 00:13

//

//  main.m

//  练习省市区用对象实现

//

//  Created by dllo on 15/11/3.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import <Foundation/Foundation.h>

#import "Operation.h"

#import "City.h"

#import "provice.h"


int main(int argc,const char * argv[]) {

    @autoreleasepool {

        Operation *oper = [[Operationalloc] init];

        [oper operation];

        [oper info];

    }

    return 0;

}

//

//  Operation.h

//  练习省市区用对象实现

//

//  Created by dllo on 15/11/4.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "City.h"

@class provice;

@class City;

@interface Operation : City

@property (nonatomic,retain)NSMutableArray *proArr;

@property (nonatomic,retain)NSArray *arr;

- (id)init;

- (void)operation;

- (void)info;

@end


//

//  Operation.m

//  练习省市区用对象实现

//

//  Created by dllo on 15/11/4.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "Operation.h"

@class provice;

@class City;

@implementation Operation

- (id)init

{

    NSString *filePath =@"/Users/dllo/Desktop/省市区/area.txt";

    NSString *str = [NSStringstringWithContentsOfFile:filePath encoding:NSUTF8StringEncodingerror:nil];

   // NSMutableArray *arr = [NSMutableArray array];

    NSArray *arr  = [strcomponentsSeparatedByString:@"\n"];

    NSMutableArray *proArr = [NSMutableArrayarray];

    self = [superinit];

    if (self) {

        [self setProArr:proArr];

        [self setArr:arr];

    }

    return self;

}

- (void)operation

{

    for (NSString *tempin self.arr) {

        if (![temp hasPrefix:@" "]) {

            provice *pro = [[provicealloc]init];

            [pro setProName:temp];

            [self.proArraddObject:pro];

        } else if([temphasPrefix:@"  "] && ![temphasPrefix:@"   "]) {

            City *city = [[Cityalloc]init];

            [[[self.proArrlastObject] cityArr]addObject:city];

            [[[[self.proArrlastObject] cityArr]lastObject]setCityName:temp];

            

        } else {

            [[[[[self.proArrlastObject] cityArr ]lastObject]quArr]addObject:temp];

        }

    }

}

- (void)info

{

    for (provice *proin self.proArr) {

        NSLog(@"%@", [proproName]);

        for (City *cityin pro.cityArr) {

            NSLog(@"%@", [citycityName]);

            for (NSString *tempin city.quArr) {

                NSLog(@"%@", temp);

            }

        }

    }

}

@end


//

//  City.h

//  练习省市区用对象实现

//

//  Created by dllo on 15/11/4.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "provice.h"


@interface City : provice


@property (nonatomic,retain)NSMutableArray *quArr;

@property (nonatomic,copy)NSString *cityName;

- (id)init;

@end


//

//  City.m

//  练习省市区用对象实现

//

//  Created by dllo on 15/11/4.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "City.h"


@implementation City

- (id)init

{

    NSMutableArray *quArr = [NSMutableArrayarray];

    NSString *cityName = [[NSStringalloc]init];

    self = [superinit];

    if (self) {

        [self setQuArr:quArr];

        [self setCityName:cityName];

    }

    return self;

}

@end


//

//  provice.h

//  练习省市区用对象实现

//

//  Created by dllo on 15/11/4.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import <Foundation/Foundation.h>


@interface provice : NSObject

@property (nonatomic,retain)NSMutableArray *cityArr;

@property (nonatomic,copy)NSString *proName;

- (id)init;

@end


//

//  provice.m

//  练习省市区用对象实现

//

//  Created by dllo on 15/11/4.

//  Copyright (c) 2015 dllo. All rights reserved.

//


#import "provice.h"


@implementation provice

- (id)init

{

    NSMutableArray *cityArr = [NSMutableArrayarray];

    NSString *proName = [[NSStringalloc]init];

    self = [superinit];

    if (self) {

        [self setProName:proName];

        [self setCityArr:cityArr];

        

    }

    return self;

}

@end



0 0
原创粉丝点击