数组学习

//

//  ViewController.m

//  Crystal Bal

//

//  Created by Vaio on 14/11/2.

//  Copyright (c) 2014 Vaio. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


- (IBAction)buttonPressed:(UIButton *)sender {

    NSLog(@"buttonPressed"); //后台打印

    //字符串学习

    NSString *myString=@"my name is Lucy";

    NSString *myStringUppercase=[myString uppercaseString];

    NSLog(@"myString =%@",myString);

    NSLog(@"myStringUppercase =%@",myStringUppercase);

    //数组学习

    NSArray *predictionArray = [NSArray alloc];

    //数组中有9个元素,索引范围是0-8 数字9超过数组索引范围

    predictionArray = [predictionArray initWithObjects:@"it is certain",

                       @"it is decidely so",

                       @"3333333",

                       @"444444",

                       @"55555555",

                       @"6666666666",

                       @"777777777777",

                       @"88888888888",

                       @"9999999999",nil];

    NSString *predictonArrayOne = [predictionArray objectAtIndex:0];

    NSString *predictonArrayFive = [predictionArray objectAtIndex:4];

    NSLog(@"predictonArrayOne = %@",predictonArrayOne);

    NSLog(@"predictionArrayFive =%@",predictonArrayFive);

    NSString *predictonArrayTen = [predictionArray objectAtIndex:9];

    NSLog(@"predictonArrayTen = %@",predictonArrayTen);

}

@end




此时报错      

2014-11-15 21:17:06.353 Crystal Bal[709:27886] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 9 beyond bounds [0 .. 8]'





解决方法为在数组中加入第十行或取消输出predictonArrayTen


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值