博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【iOS学习笔记】02-Foundation Kit
阅读量:4935 次
发布时间:2019-06-11

本文共 2759 字,大约阅读时间需要 9 分钟。

在iOS学习过程中,我们需要用到很多基本数据类型,我们先学习Foundation Kit,Foundation Kit是中比较重要的组件。

首先在你的代码中要包含下面这句话,然后在程序中,才可以引用。

 1 #import <Foundation/Foundation.h> 

 

1. 字符串

NSString

NSString *height;height = [NSString stringWithFormat:@"Your height is %d feet, %d inches", 5, 11];

字符串比较

NSString *thing1 = @"hello 5";NSString *thing2 = [NSString stringWithFormat: @"hello %d", 5];if([thing1 isEqualToString: thing2]){  NSLog(@"The strings are the same!");}if(thing1 == thing2){    NSLog(@"They are the same object!");}

 不区分大小写比较

if([thing1 compare: thing2 options: NSCaseInsensitiveSearch | NSNumericSearch] == NSOrderedSame){    NSLog(@"They match!");}

Contains

NSString *fileName = @"draft-chapter.pages";                if([fileName hasPrefix:@"draft"])        {            NSLog(@"this is a draft");        }                if([fileName hasSuffix:@".mov"])        {            NSLog(@"this is a movie");        }                if([fileName containsString:@"chapter"])        {            NSLog(@"this is a chapter");        }

 NSString same with java's String, NSMutableString same with Java's StringBuffer.

NSMutableString *friends = [NSMutableString stringWithCapacity:50];        [friends appendString:@"James BethLynn Jack Evan"];                NSRange jackRange = [friends rangeOfString:@"Jack"];        jackRange.length++; //eat the space that follows                [friends deleteCharactersInRange:jackRange];                NSLog(friends);

 

 

2. 集合大家族

Array

     NSArray *array = [NSArray arrayWithObjects:@"one", @"two", @"three", nil]; //That is why we cannot use nil as a element                //the other way        NSArray *array2 = @[@"one", @"two", @"three"];                for (NSInteger i = 0; i < [array count]; i++) {            NSLog(@"index %d has %@.", i, [array objectAtIndex:i]);        }                for (NSInteger i = 0; i < [array2 count]; i++) {            NSLog(@"index %d has %@.", i, array2[i]);        }                //Split String to Array        NSString *string = @"oop:ack:bork:greeble:ponies";        NSArray *chunks = [string componentsSeparatedByString:@":"];        for (NSInteger i = 0; i < [chunks count]; i++) {            NSLog(@"index %d has %@.", i, chunks[i]);        }

 NSMutableArray

NSMutableArray *array = [NSMutableArray arrayWithCapacity:17];        for (NSInteger i = 0; i < 4; i++) {            NSObject *o = [NSObject new];            [array addObject:o];        }

 

NSEnumeratoer

NSEnumerator *enumerator = [array objectEnumerator];        while (id thingie = [enumerator nextObject]) {            NSLog(@"I found %@", thingie);        }                for (NSString *string in array) {            NSLog(@"I found %@", string);        }

 

 

3. 其他数值

NSNumber

NSValue

NSNull

转载于:https://www.cnblogs.com/baoguo/articles/4594078.html

你可能感兴趣的文章
自定义RatingBar的一个问题(只显示显示一个星星)
查看>>
剑指Offer--二叉树的镜像
查看>>
PAT-BASIC-1031-查验身份证
查看>>
Python笔记5----集合set
查看>>
连连看小游戏
查看>>
js二级联动
查看>>
谜题32:循环者的诅咒
查看>>
RMI
查看>>
动态切换多数据源的配置
查看>>
win7电脑调整分区后分区不见的文件寻回法子
查看>>
《第一行代码》学习笔记2-Android开发特色
查看>>
bzoj3396 [Usaco2009 Jan]Total flow 水流
查看>>
20165231 2017-2018-2 《Java程序设计》第3周学习总结
查看>>
(180905)如何通过梯度下降法降低损失----Google机器学习速成课程笔记
查看>>
(响应式PC端媒体查询)电脑屏幕分辨率尺寸大全
查看>>
Crystal Reports拉报表报错:Error detected by database DLL
查看>>
Java获取新浪微博cookies
查看>>
面试题总结
查看>>
【BZOJ1095】捉迷藏(动态点分治)
查看>>
Table Basics [转载]
查看>>