nsarray

Convert NSArray to NSString in Objective-C

随声附和 提交于 2019-12-17 05:22:26
问题 I am wondering how to convert an NSArray [@"Apple", @"Pear ", 323, @"Orange"] to a string in Objective-C . 回答1: NSString * result = [[array valueForKey:@"description"] componentsJoinedByString:@""]; 回答2: One approach would be to iterate over the array, calling the description message on each item: NSMutableString * result = [[NSMutableString alloc] init]; for (NSObject * obj in array) { [result appendString:[obj description]]; } NSLog(@"The concatenated string is %@", result); Another

Convert NSArray to NSString in Objective-C

别说谁变了你拦得住时间么 提交于 2019-12-17 05:22:05
问题 I am wondering how to convert an NSArray [@"Apple", @"Pear ", 323, @"Orange"] to a string in Objective-C . 回答1: NSString * result = [[array valueForKey:@"description"] componentsJoinedByString:@""]; 回答2: One approach would be to iterate over the array, calling the description message on each item: NSMutableString * result = [[NSMutableString alloc] init]; for (NSObject * obj in array) { [result appendString:[obj description]]; } NSLog(@"The concatenated string is %@", result); Another

Finding smallest and biggest value in NSArray of NSNumbers

萝らか妹 提交于 2019-12-17 02:42:56
问题 What's an effective and great way to compare all the values of NSArray that contains NSNumbers from floats to find the biggest one and the smallest one? Any ideas how to do this nice and quick in Objective-C? 回答1: If execution speed (not programming speed ) is important, then an explicit loop is the fastest. I made the following tests with an array of 1000000 random numbers: Version 1: sort the array: NSArray *sorted1 = [numbers sortedArrayUsingSelector:@selector(compare:)]; // 1.585 seconds

Deep copying an NSArray

南笙酒味 提交于 2019-12-17 00:48:06
问题 Is there any built-in function that allows me to deep copy an NSMutableArray ? I looked around, some people say [aMutableArray copyWithZone:nil] works as deep copy. But I tried and it seems to be a shallow copy. Right now I am manually doing the copy with a for loop: //deep copy a 9*9 mutable array to a passed-in reference array -deepMuCopy : (NSMutableArray*) array toNewArray : (NSMutableArray*) arrayNew { [arrayNew removeAllObjects];//ensure it's clean for (int y = 0; y<9; y++) { [arrayNew

How to show 3 events on same date on calendar from web service in Objective C

倖福魔咒の 提交于 2019-12-14 03:44:45
问题 I am new in iOS and I am facing problem regarding to show multiple events on same date.I am using JTCalendar. My code is like this In ViewDidLoad _calendarManager = [JTCalendarManager new]; _calendarManager.delegate = self; [self createMinAndMaxDate]; [_calendarManager setMenuView:_calendarMenuView]; [_calendarManager setContentView:_calendarContentView]; [_calendarManager setDate:_todayDate]; In viewWillAppear I code to change colour according to web service [self

Check if NSString hasPrefix that is contained in NSArray

不想你离开。 提交于 2019-12-14 02:05:16
问题 I have this if statement to check if a URL starts with a prefix: NSString *baseUrl = @"http://example.com/"; NSString *currentURL = @"http://example.com/confirm"; if( [currentURL hasPrefix:[baseUrl stringByAppendingString:@"confirm"]] ){ // True, so do something... } I would like to modify the hasPrefix part of my if statement so that it returns true if currentUrl is appended by ANY of the values in my NSArray shown here: NSArray *pages = [NSArray arrayWithObjects:@"confirm",@"products",nil];

Group NSDictionary by dates [duplicate]

非 Y 不嫁゛ 提交于 2019-12-14 01:46:09
问题 This question already has answers here : Grouping NSArray of NSDictionary based on a key in NSDictionay (2 answers) Closed 5 years ago . I have a NSDictionary and i want to group it creating an array of objects by date Example of the main NSDictionary: ({ date = "2014-04-27"; group = "yellow.png"; length = 180; }, { date = "2014-04-28"; group = "blue.png"; length = 180; }, { date = "2014-04-27"; group = "blue.png"; length = 120; }) I want to group something similar as: 2014-04-27 = ( { date =

Why Doesn't NSArray return NULL for nonexistent indexes?

强颜欢笑 提交于 2019-12-14 01:01:17
问题 The way I understand it one of the things special about Objective C is that you can send messages to NULL and it will just ignore them instead of crashing. Why is it that NSArray doesn't just return a NULL object if the index requested is out of bounds instead of causing a NSRangeException? What I would expect from Objective C and NSArray is the following. NSArray *array = [NSArray arrayWithObjects:@"Object 1", @"Object 2", @"Object 3", nil]; for (int i = 0; i < 5; i++) { NSString *string =

Copy NSMutablearray to another

[亡魂溺海] 提交于 2019-12-14 00:24:15
问题 I am trying to copy NSMutableArray to another but it does not show me anything at the UITableView : NSMutableArray *objectsToAdd= [[NSMutableArray alloc] initWithObjects:@"one",@"two"]; NSMutableArray *myArray = [[NSMutableArray alloc] initWithObjects:objectsToAdd,nil]; NSMutableArray *list = [[NSMutableArray alloc] init]; [self.list addObjectsFromArray:myArray]; Nothing show up! What is wrong? It crashes my app because I do not have nil at my NSMutableArray how can I add nil to it? addobject

NSArray clears after 3 times view did load

只愿长相守 提交于 2019-12-13 22:17:35
问题 I have an NSArray that contains a couple of items. The NSArray is loaded into a uitableview from another class. when I back out of the detail view and re-enter (for the 3rd time), the NSArray is empty and the tableview is empty as well. What is happening? (I am using arc so I don't think it is a leak) - (void)viewDidLoad { myMatch = [[Match alloc] initWithId:1 OpponentId:13]; } - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString