`
xumingrencai
  • 浏览: 1183429 次
文章分类
社区版块
存档分类
最新评论

加载字符串到 NSMutableDictionary 示例

 
阅读更多

// 加载每个关卡钟表走动的时间~

-(void) loadLevelDurationTime {

_levelDurationTimeData = [[NSMutableArray alloc] init];

int levelTotalCount = [_gCfg ifk:@"levelTotalCount"];

for(int i = 0; i < levelTotalCount; i ++) {

[_levelDurationTimeData addObject:@"10"]; // 每关默认10秒钟,如果配置文件中有做配置,则将默认覆盖掉~

}

NSString *absPath = [[NSBundle mainBundle] pathForResource:@"levelDuration" ofType:@"txt"];

NSFileManager *fm = [NSFileManager defaultManager];

if([fm fileExistsAtPath:absPath] == NO) {

NSLog(@"File not exists!");

return;

}

NSString *fileContent = [NSString stringWithContentsOfFile:absPath

encoding:NSUTF8StringEncoding

error:nil];

// NSLog(@"file contents:\n%@", fileContent);

NSArray *cfgTime = [fileContent componentsSeparatedByString:@"\n"];

int lessLength = MIN( [cfgTime count], [_levelDurationTimeData count] );

for(int i = 0; i < lessLength; i ++) {

[_levelDurationTimeData replaceObjectAtIndex:i withObject:[cfgTime objectAtIndex:i]];

// NSLog(@"%d关的等待时间长度为: %@", i, [_levelDurationTimeData objectAtIndex:i]);

}

}


// 加载sprite动画的顶点信息~

-(void) loadAnimationData {

_animVerticesDic = [[NSMutableDictionary alloc] initWithCapacity:20];

NSString *absPath = [[NSBundle mainBundle] pathForResource:@"animVerticesSummary" ofType:@"txt"];

NSFileManager *fm = [NSFileManager defaultManager];

if([fm fileExistsAtPath:absPath] == NO) {

NSLog(@"File not exists!");

return;

}

NSString *fileContent = [NSString stringWithContentsOfFile:absPathencoding:NSUTF8StringEncodingerror:nil];

NSArray *verticesSummaryArray = [fileContent componentsSeparatedByString:@"\n"];

int len = [verticesSummaryArray count];

for(int i = 0; i < len; i ++) {

NSString *unit = [verticesSummaryArray objectAtIndex:i];

NSRange range = [unit rangeOfString:@"="];

// NSLog(@"range.location=%d, range.length=%d", range.location, range.length);

NSString *keyStr = [unit substringToIndex:range.location];

// NSLog(@"keyString: %@", keyStr);

NSString *valueStr = [unit substringFromIndex:range.location+1];

// NSLog(@"valueString: %@", valueStr);

[_animVerticesDic setObject:valueStr forKey:keyStr];

}

}

分享到:
评论

相关推荐

    NSDictionary_NSMutableDictionary

    1.字典使用Key-Value的形式储存数据,是关键字及其定义(描述)的集合 2.字典中的对象储存没有顺序,使用key来表示每个对象,key唯一,Value值可相同 3.字典里Value值在前,key在后 Cocoa中的实现字典的集合...

    顺序版NSMutableDictionary

    顺序版NSMutableDictionary

    safely安全使用NSArray,NSMutableArray,NSDictionary,NSMutableDictionary,NSMutableString。-Swift开发

    功能安全访问NSArray安全访问NSDictionary安全访问并对NSMutableArray进行更改安全访问并对NSMutableDictionary进行更改安全访问并对NSMutableString进行更改要求iOS 8.0+ / macOS 10.13.6+ Xcode 10.1(10B61)+...

    MACollections:重新实现一些可可收藏,用于教育目的

    这些是NSMutableArray和NSMutableDictionary示例实现。 它们不依赖于现有的具体实现,而是“从头开始”的,因为它们直接使用更多原始结构来实现数组/哈希表。 这些主要用于教育目的。 这里讨论了MAMutableArray实现...

    NSDictionary-Enhance:NSDictionary NSMutableDictionary 增强

    NSDictionary NSMutableDictionary 增强 Import pod 'NSDictionary-Enhance', '~&gt; 1.0.0' Usage #import "NSDictionary+VDEnhance.h" [NSDictionary vd_dictionaryWithDictionary:originDic mergeWithDictionary:dic...

    datasnap-ios:ios sdk 和示例

    数据快照客户端 供应商中立 iOS 示例应用程序和 SDK 文档: 有关事件类型的更多信息,请参阅 。 快速开始 #import "DataSnapClient/DSIOClient.h"在你的源... NSMutableDictionary *beaconSighting = [ NSMutableDic

    复杂XML的解析及组装

    此包可以解决XML文件的解析、对象转化为XML字符串的问题。 1 通过调用解析类,可以将XML的DATA数据转换为XmlNode对象,XmlNode以树形结构进行XML的数据封装,使用的时候按照树形结构进行数据的获取。(如有问题请...

    UIWebView的使用代码

    方法,可以在objective-c代码中调用javascript代码,参数script字符串保存了所要执行的js代码字符串,执行结果以字符串形式返回。以获取web页面标题为例,代码如下: ? 1 NSString *pageTitle = [webView ...

    Objective-c解析XML封装

    示例见最后的注释。 XML封装类待续。。。 转载请注明来源,谢谢 ====== XmlResolve.h #import &lt;Foundation/Foundation.h&gt; @interface XmlResolve : NSObject { } @property (nonatomic, retain)...

    (objective-c 自定义 NSDictionary 键类的注意事项)工程

    详情请参见我的博文: http://blog.csdn.net/yang3wei/article/details/7804171

    plist文件是标准的xml文件

    NSMutableDictionary* dict = [ [ NSMutableDictionary alloc ] initWithContentsOfFile:@"/Sample.plist" ]; [ dict setObject:@"Yes" forKey:@"RestartSpringBoard" ]; [ dict writeToFile:@"/Sample.plist" ...

    objc-aatree:作为 NSMutableDictionary 的 Arne Andersson (AA) 平衡二叉搜索树的线程安全的 Objective-C 实现

    此类是NSMutableDictionary类集群的扩展,因此您期望从 Foundation Collections 获得的所有方法(主要在NSMutableDictionary公共抽象接口中)也可以在此类上调用,除了初始化方法。 该类支持,除其他外, NSCopying...

    Objective-C---How-to-Create-And-Use-NSDictionary-And-NSMutableDictionary-Latest-2017-Hindi-:源代码-How to use the source code

    Objective-C-如何创建和使用NSDictionary和NSMutableDictionary-Latest-2017-Hindi- 视频:-Yogesh Patel在Objective-C中使用NSDictionary和NSMutableDictionary的介绍。 在本频道中,我将在多部视频中讲授大多数...

    Objective-c对象组装XML

    4 利用解析类解析并展现到UIView 部分代码如下: @implementation XmlPackage @synthesize obj; @synthesize isList; @synthesize xmlString; @synthesize objectName; @synthesize lvUp; @synthesize root; @...

    TYDB:适用于iOS的最简单SQLite管理器

    适用于iOS的最简单SQLite管理器。 设定说明 ...NSMutableDictionary *data = [[ NSMutableDictionary alloc ] init ]; [data setObject: @" Yash " forKey: @" Name " ]; [data setObject: @" yash

    登陆注册实现demo

    NSMutableDictionary *usernamepasswordKVPairs = [NSMutableDictionary dictionary]; [usernamepasswordKVPairs setObject:txtfldUsername.text forKey:KEY_USERNAME]; [usernamepasswordKVPairs setObject:...

    cocoa something related

    &gt; NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; &gt; [parameters setObject:mainPort forKey:@"port"]; &gt; &gt; // start the secondary threads &gt; // loop starts at 1 because the main thread...

    plist 读取和写入(增删改)

    plist 读取和修改(增删改) 纠结了很久关于NSMutableDictionary的添加,其实这个NSMutableDictionary的修改方法一样的。我找plist的读取写入找了好久都没找到demo,今天就自己写了一个跟大家分享一下

    iOS Crash防护

    iOS Crash防护内容涉及 NSArray/NSMutableArray、NSDictionary/NSMutableDictionary、NSString/NSMutableString、Unrecognized Selector、KVO、KVC 、野指针定位、内存泄漏/循环引用;主要是对常见易错的地方进行...

Global site tag (gtag.js) - Google Analytics