nsarray

Why does fast enumeration not skip the NSNumbers when I specify NSStrings?

别等时光非礼了梦想. 提交于 2019-12-19 09:06:36
问题 I thought that I knew how to use fast enumeration, but there is something I don't understand about it. If I create three NSString objects and three NSNumber objects and put them in an NSMutableArray : NSString *str1 = @"str1"; NSString *str2 = @"str2"; NSString *str3 = @"str3"; NSNumber *nb1 = [NSNumber numberWithInt:1]; NSNumber *nb2 = [NSNumber numberWithInt:2]; NSNumber *nb3 = [NSNumber numberWithInt:3]; NSArray *array = [[NSArray alloc] initWithObjects:str1, str2, str3, nb1, nb2, nb3, nil

Storing NSArray in UIPasteboard

青春壹個敷衍的年華 提交于 2019-12-19 07:35:49
问题 I have several text files which I want to transfer between 2 Apps. (ie. free and paid versions of the same App). I'm using UIPasteboard to do this. The contents of the files are held in memory as NSArrays, and so I want to copy these NSArrays to the pasteboard (lite version), and read them from the pasteboard (full version). For some reason the data cannot be read back from the pasteboard. The data is being returned as a NSData object, rather than NSArray, which I think means that it is not

Storing NSArray in UIPasteboard

断了今生、忘了曾经 提交于 2019-12-19 07:35:22
问题 I have several text files which I want to transfer between 2 Apps. (ie. free and paid versions of the same App). I'm using UIPasteboard to do this. The contents of the files are held in memory as NSArrays, and so I want to copy these NSArrays to the pasteboard (lite version), and read them from the pasteboard (full version). For some reason the data cannot be read back from the pasteboard. The data is being returned as a NSData object, rather than NSArray, which I think means that it is not

Sort NSMutableArray with strings that contain numbers?

徘徊边缘 提交于 2019-12-19 03:21:33
问题 I have a NSMutableArray and it has the users high scores saved into it. I want to arrange the items numerically (the numbers are stored in NSStrings.) Example: 4,2,7,8 To 2,4,7,8 What is the simplest way to do this if the data is stored in NSStrings? 回答1: This code will do it: //creating mutable array NSMutableArray *myArray = [NSMutableArray arrayWithObjects:@"4", @"2", @"7", @"8", nil]; //sorting [myArray sortUsingComparator:^NSComparisonResult(NSString *str1, NSString *str2) { return [str1

Want smooth transition or slide between pictures in an NSArray using UISwipeGesture

时间秒杀一切 提交于 2019-12-19 03:15:53
问题 I have a UIImageView as one of my tabbarcontroller views, and I've added a UISwipeGestureRecognizer (right and left) to navigate through a series of photos in an NSArray. However, when swiping it jumps from photo to photo with no smooth transition. I'm not after anything fancy, but even a slide animation would be okay, like as one photo slides in, the other is sliding out the other side. Is this possible with the UISwipeGestureRecgonizer and an NSArray? 回答1: The standard solution is to use a

sorting an NSArray of NSDates

夙愿已清 提交于 2019-12-18 15:12:09
问题 I have an NSArray of NSDate objects and I want to sort them so that today is at 0, yesterday at 1 etc. Is it ascending or descending, and do i use a function, selector or what? 回答1: There are different sort methods for NSArray because there may be different ways you want to sort things. NSSortDescriptors are a general way that give you a lot of options as far as what keys to use in sorting, what selectors you want to use on those keys, and overall order to use, etc. Or you can use functions

iOS sort an NSArray of Time NSString's

倖福魔咒の 提交于 2019-12-18 13:36:22
问题 I need to sort an NSArray containing time NSString 's such as, NSMutableArray *times = [[NSMutableArray alloc]initWithObjects:@"09:00 AM",@"07:30 AM",@"06:45 PM",@"05:00 PM",@"12:45 AM",@"12:45 PM",@"01:00 AM",@"01:15 PM", nil]; What I need is to sort the array in ascending order of time. Is there any way to do such a thing? 回答1: NSMutableArray *times = [[NSMutableArray alloc]initWithObjects:@"09:00 AM",@"07:30 AM",@"06:45 PM",@"05:00 PM",@"12:45 AM",@"12:45 PM",@"01:00 AM",@"01:15 PM", nil];

iOS how to debug crashes without a stack trace like : [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array?

拟墨画扇 提交于 2019-12-18 13:16:22
问题 I'm trying to dismiss a modal view controller and am getting the following error: * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' At one point I spent 4 hours trying to debug such error. Can anyone tell me if there's a way to look at stack traces for such errors to understand which object caused the incorrect access? Thank you! 回答1: In Xcode 4 you can set an exception breakpoint in the breakpoint

How to check if an instance of NSMutableArray is null or not

最后都变了- 提交于 2019-12-18 12:10:48
问题 How to check an NSMutableArray is null or not ? 回答1: If you want to check if it is empty: if ([myMutableArray count] == 0) { ... } If you want to check if the variable is nil : if (!myMutableArray) { ... } or: if (myMutableArray == nil) { ... } 回答2: //if the array has a count of elements greater than 0, then the array contains elements if(myarray.count>0){ NSlog(@"myarray contains values/elements"); } else{ //else the array has no elements NSlog(@"myarray is nil"); } 回答3: There are multiple

Filter an NSArray which contains custom objects

北战南征 提交于 2019-12-18 12:02:15
问题 I have UISearchBar , UITableView , a web service which returns a NSMutableArray that contain objects like this: //Food.h Food : NSObject { NSString *foodName; int idFood; } @property (nonatomic, strong) NSString *foodName; And the array: Food *food1 = [Food alloc]initWithName:@"samsar" andId:@"1"]; Food *food2 = [Food alloc] initWithName:@"rusaramar" andId:@"2"]; NSSarray *array = [NSArray arrayWithObjects:food1, food2, nil]; How do I filter my array with objects with name beginning with "sa"