ios developer tiny share-20161026
来源:互联网 发布:店铺优化是什么意思 编辑:程序博客网 时间:2024/05/16 14:29
今天讲Objective-C的两个小知识点,分别是NSDictionary和NSNull,NSDictionary接上节,我们讲NSDictionary的检索,可变的NSDictionary,NSMutilateDictionary。
Querying Dictionaries
Once you’ve created a dictionary, you can ask it for the object stored against a given key, like this:
NSNumber *storedNumber = [dictionary objectForKey:@"magicNumber"];
If the object isn’t found, the objectForKey: method will return nil.
There’s also a subscript syntax alternative to using objectForKey:, which looks like this:
NSNumber *storedNumber = dictionary[@"magicNumber"];
Mutability
If you need to add or remove objects from a dictionary after creation, you need to use the NSMutableDictionary subclass, like this:
[dictionary setObject:@"another string" forKey:@"secondString"];[dictionary removeObjectForKey:@"anObject"];
Represent nil with NSNull
It’s not possible to add nil to the collection classes described in this section because nil in Objective-C means “no object.” If you need to represent “no object” in a collection, you can use the NSNull class:
NSArray *array = @[ @"string", @42, [NSNull null] ];
NSNull is a singleton class, which means that the null method will always return the same instance. This means that you can check whether an object in an array is equal to the shared NSNull instance:
for (id object in array) {if (object == [NSNull null]) {NSLog(@"Found a null object");}}
0 0
- ios developer tiny share-20161026
- ios developer tiny share-20160628
- ios developer tiny share-20160629
- ios developer tiny share-20160630
- ios developer tiny share-20160701
- ios developer tiny share-20160704
- ios developer tiny share-20160705
- ios developer tiny share-20160706
- ios developer tiny share-20160707
- ios developer tiny share-20160708
- ios developer tiny share-20160711
- ios developer tiny share-20160712
- ios developer tiny share-20160713
- ios developer tiny share-20160714
- ios developer tiny share-20160715
- ios developer tiny share-20160718
- ios developer tiny share-20160719
- ios developer tiny share-20160720
- com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: 1 字节的 UTF-8 序列的字节 1 无效。
- float布局和position布局的简单区别
- NOIP2016模拟赛 day6
- 各大排序算法性能比较
- Linux 使用
- ios developer tiny share-20161026
- 不知道是第几次遇到outofmemory错误
- mysql 日志文件
- 【jzoj4868】【Simple】【数论】
- Qt 储存软件窗口最后的关闭时的状态
- PHP常用的四种排序
- 雅思写作中地道的转折方式
- 一天一条Linux指令-top
- Android添加事件到日历