objective-c(架構)

來源:互聯網
上載者:User

標籤:

架構指objective-c的foundation庫,下面的例子中給出幾個常見用的類及其方法。

  • 數值對象
        NSNumber *intNum;        NSNumber *longNum;        NSNumber *floatNum;                intNum = [NSNumber numberWithInteger:12];        NSLog(@"%i", [intNum integerValue]);                longNum = [NSNumber numberWithLong:0x123456];        NSLog(@"%lx", [longNum longLongValue]);                floatNum = [NSNumber numberWithFloat:12.00];        NSLog(@"%f", [floatNum floatValue]);                if([intNum isEqualToNumber:floatNum] == YES){            NSLog(@"eqaul"); //相同        }else{            NSLog(@"not equal");        } 
  •  字串
        NSString *str1 = @"hello,world";        NSString *str2 = [NSString stringWithFormat:@"%i,%@", 5, @"fredric"];        NSLog(@"%@%@", str1,str2);        NSLog([str1 stringByAppendingString:str2]);                NSMutableString *str3 = [NSMutableString stringWithString:@"hello"];        [str3 appendString:@"fredric_"];        [str3 insertString:@"word" atIndex:str3.length];        NSLog(@"%@",str3); //hellofredric_word                NSRange res = [str3 rangeOfString:@"ric"];        if(res.location != NSNotFound){            [str3 deleteCharactersInRange:res];        }                NSLog(@"%@",str3); //hellofred_word
  • 數組
       NSArray *array = [NSArray arrayWithObjects:@"demo1",@"demo2",@"demo3", nil];                for(int i = 0; i < [array count]; i++){            NSLog(@"%@",[array objectAtIndex:i]);        }                NSMutableArray *mArray = [NSMutableArray arrayWithCapacity:3];        [mArray addObject:@"demo4"];        [mArray addObject:@"demo5"];        [mArray addObject:@"demo6"];                for(int i = 0; i < [mArray count]; i++){            NSLog(@"%@",[mArray objectAtIndex:i]);        }
  • 字典
        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:@"value1",@"key1",@"value2",@"key2",@"valu3", @"key3", nil];        NSString *value1 = [dic objectForKey:@"key1"];        NSLog(@"%@", value1);                NSMutableDictionary *mDic = [[NSMutableDictionary alloc]init];        [mDic setObject:@"value1_1" forKey:@"key1"];        NSLog(@"%@", [mDic objectForKey:@"key1"]);

objective-c(架構)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.