摘要:Is there an integer vector struct in Cocoa or should I define my own?I am keeping track of pairs of ints and NSUIntegers as array indexes and other things.Is there something analogous to CGPoint that is already defined?I'm doing graphics stuff on iPhone if it matters.It's fairly easy to defi
阅读全文
摘要:创建.plist文件并存储 NSString *errorDesc; //用来存放错误信息 NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:4]; //NSDictionary, NSData等文件可以直接转化为plist文件 NSDictionary *innerDict; NSString *name; Player *player; NSInteger saveIndex; for(int i = 0; i < [playerArray count]; i++) { pl...
阅读全文
摘要://// codeObj.h// encodeObject//// Created by 110 on 10-2-6.// Copyright 2010 __MyCompanyName__. All rights reserved.//#import <Cocoa/Cocoa.h>@interface codeObj : NSObject <NSCoding>{NSString *name;int magicNumber;float shoseSize;NSMutableArray *subThingies;}@property (copy) NSString *nam
阅读全文
摘要:我们在C/C++开发中常会用到结构体来帮助我们简单封装基本数据类型,在Objective-C中我们也可以使用结构体来完成数据类型的封装。同时,Cocoa Touch还提供了一个NSValue来帮助我们更好地在开发中使用结构体。 我们可以使用NSValue来辅助我们实现一些简单数据结构的封装。比如我们定义了一个简单的结构体类型typedef struct { int id, float height, unsigned char flag}MyTestStruct; 此时,我们就可以使用MyTestStruct这个结构体来很容易地封装数据。如 MyTestStruct myTestStruct;
阅读全文
摘要:NSData和结构体struct之间如何转换用处是当用NSNotification传递数据时需要这个转换,然后把NSData放到userInfo中。// make a NSData objectNSData *myData = [NSData dataWithBytes:&myPacketJoin length:sizeof(myPacketJoin)];// make a new PacketJoinPacketJoin newJoin;[myData getBytes:&newJoin length:sizeof(newJoin)];struct msg {uint32_t
阅读全文
摘要:1 #import <Foundation/Foundation.h> 2 3 typedef enum { 4 item = 0 , 5 image = 1 , 6 avatar = 2 7 } sandboxItemtype; 8 9 10 @interface UpdateManager : NSObject {11 sandboxItemtype _itemType;//存储信息类型,暂时没用上12 NSString *_filePath;//记录更新日志存储路径13 NSString *_timePath;14 NSStr...
阅读全文
摘要:在所有的移动开发平台数据持久化都是很重要的部分:在j2me中是rms或保存在应用程序的目录中,在symbian中可以保存在相应的磁盘目录中和数据库中。symbian中因为权限认证的原因,在3rd上大多数只能访问应用程序的private目录或其它系统共享目录。在iphone中,apple博采众长,提供了多种数据持久化的方法,下面笔者会逐个进行详细的讲解。iphone提供的数据持久化的方法,从数据保存的方式上讲可以分为三大部分:属性列表、对象归档、嵌入式数据库(SQLite3)、其他方法。一、属性列表NSUserDefaultsNSUserDefaults类的使用和NSKeyedArchiver有
阅读全文
摘要:- (NSMutableArray *)loadMarkersFromFilePath:(NSString *)filePath { NSMutableArray *markers = nil; if (filePath == nil || [filePath length] == 0 || [[NSFileManager defaultManager] fileExistsAtPath:filePath] == NO) { markers = [[[NSMutableArray alloc] init] autorelease]; } else { NSData *data = [[N...
阅读全文
摘要:# Objective-C做的一个Framework跟App整合到一起,因为用到了多线程,所以通信不可避免,但是Framework里又载入了一个C++的Plugin,里面有许多struct,在把这类struct变成对象序列化时遇到问题。以前做的很傻,把struct的所有成员用NSDictionary来一个个封装,再一个个反序列化,好傻呀。要是struct定义变了,那代码就又要修改了~所以重构了一下,这里给出怎样对non object数据结构进行对象封装和序列化。怎样进行封装是引用JongAm‘s一篇博文。原文地址:http://jongampark.wordpress.com/2008/08/
阅读全文
摘要:在在界面中显示文本内容中写入UITextView的文本,如何保存?可以使用NSUserDefaults:NSUserDefaults *textData;该实例实际上是NSDirectory,保存键值对。在使用中,首先检查是否有该键值对,如果有赋值给TextView的text属性。- (void) initTextView{ textData=[NSUserDefaults standardUserDefaults]; textview=[[UITextView alloc] initWithFrame:CGRectMake(550, 140, 400, 300)]; textview.bac
阅读全文
摘要:NSArray 对象保存NSString *strOne = @"Persistent data1";NSString *strTwo = @"Persistent data 2";NSMutableArray *persistentArray = [[NSMutableArray alloc] init];[persistentArray addObject:strOne];[persistentArray addObject:strTwo];NSArray *filePathArray = NSSearchPathForDirectoriesInDo
阅读全文
摘要:使用Cocoa保存XML格式记录文件是本文要介绍的内容,在Cocoa中保存XML的属性列表文件(plist)是很容易的事情。NSArray,NSDictionary, NSString, 或者 NSData都可以保存为XML格式的plist文件。如果NSArray或者NSDictionary中还包含其他可以保存为属性列表的对象,它们可以一起存储在plist文件中。下面是保存的方法:@interfaceClientDisplayMgr{ … IBOutletidm_clientName;//outletstotextboxesinthepreferences IBOutletidm_server
阅读全文