nsmutablearray

Convert array to NSAttributedString

狂风中的少年 提交于 2019-12-06 05:51:55
I have a NSMutableArray composed of NSAttributedString 's. I'm trying to convert it to a single NSAttributedString separating all the NSAttributedString 's with a character. This approach is similar to the conversion of an array to a NSString with the componentsJoinedByString:@"," method but unfortunately this method doesn't exist with the NSAttributedString . How can I convert the array? Thanks. I'd to the old way: NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] init]; NSAttributedString *jointElement = [[NSAttributedString alloc] initWithString:@","] for (int i = 0; i

Split NSArray into sub-arrays based on NSDictionary key values

谁都会走 提交于 2019-12-06 05:46:33
问题 We have an app that calls a SOAP web service and retrieves a long list of XML, which the app then parses into an NSArray of NSDictionary objects. The NSArray contains a list of Rental Apartment information, each of which is stored into an NSDictionary . The entire list may contain 10 different types of Apartments (i.e. 2-room, 3-room), and we need to split the NSArray into smaller NSArray s based on Room-Type, which has the key "roomType" in the NSDictionary objects. Currently our algorithm

Implementing Custom NSMutableArray

情到浓时终转凉″ 提交于 2019-12-06 05:45:33
I would like to create my own custom NSMutableArray of my custom objects: @interface Course : NSObject { NSString *className; NSString *classGrade; NSInteger creditHours; } This class will store an array of courses : @interface AllCourses : NSObject : NSMutableArray{ NSMutableArray *arrClasses; } I would like "AllCourses" to inherit from NSMutableArray so i can use it like any other NSMutableArray Object and add\remove courses from it and load it into a tableView etc... So my question is ,if u would be so kind, is what my implementation of "AllCourses" should look like ? Lorenzo B First of all

Cocoa Touch Question. Should [NSMutableArray array] be retained?

戏子无情 提交于 2019-12-06 05:23:18
问题 Here is the gist of some code I'm writing. I'm concerned that I am not properly addressing the retain/release issues with the array class method on NSMutableArray. Is the following actually leaking memory? for(a while) { // do stuff NSMutableArray *a = nil; // do stuff if (!a) { a = [NSMutableArray array]; } } // for(a while) 回答1: You wouldn't leak memory in this code, and releasing the array yourself will cause a crash when the array is autoreleased at the end of the run loop. Most Cocoa

How to check a uiviewcontroller is present in uinavigationcontroller stack

安稳与你 提交于 2019-12-06 05:09:20
问题 I have a UINavigationController . I have to pop a view from a UINavigationController and replace it with another view. How we can search for a UIViewController object and replace it with another ? when i print NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: myDelegate.navigationController.viewControllers]; I tried.. [allViewControllers removeObjectIdenticalTo: @"NonLogginedViewController"]; [allViewControllers removeObjectIdenticalTo: myDelegate.nonLogginedViewController]

NSMutableArray removeAllObjects beyond bounds exception

柔情痞子 提交于 2019-12-06 04:57:03
I have an NSMutableArray object called logBuffer, which holds log information and dumps it in a file every N lines. When that happens, I remove all its entries, with [logBuffer removeAllObjects] Sometimes this throws an exception: [__NSArrayM removeObjectAtIndex:]: index 7 beyond bounds [0 .. 6] I guess removeAllObjects internally iterates through all objects in the array, but I am not sure how it can go beyond its bounds. My only though is that there is another thread that manipulates the array while the objects are being removed, but I am not sure at all. Any thoughts? EDIT: Here's some

Adding items to NSMutableArray and saving/loading

安稳与你 提交于 2019-12-06 04:18:41
I've used this tutorial to create an app with a table view that is populated using an NSMutableArray. Now I'd like to add the functionality to add additional items to the array and save/load them. I've customized the Fruit class to look like this: #import <UIKit/UIKit.h> @interface Fruit : NSObject { NSString *name; NSString *instructions; NSString *explination; NSString *imagePath; } @property(nonatomic,copy) NSString *name; @property(nonatomic,copy) NSString *instructions; @property(nonatomic,copy) NSString *explination; @property(nonatomic,copy) NSString *imagePath; - (id)initWithName:

Sorting Array alphabetically [duplicate]

限于喜欢 提交于 2019-12-06 03:50:57
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How to sort a NSArray alphabetically? Hi all, I have an array which consist of companies name. I want to sort array alphabetically so that companies name come in alphabetic order. Please suggest me how to do this. Thanks in advance 回答1: [myArray sortUsingSelector:@selector(caseInsensitiveCompare:)]; 回答2: NSArray *sortedStrings = [strings sortedArrayUsingSelector:@selector(compare:)]; 回答3: See this....

NSPredicate - case insensitive filtering for multiple conditions

左心房为你撑大大i 提交于 2019-12-06 02:59:53
问题 I'm using following NSPredicate for filtering, NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(firstName CONTAINS %@ ) OR (lastName CONTAINS %@ )OR (UserName CONTAINS %@ ) ", myText,myText,myText]; NSArray *filtered = [responseArray filteredArrayUsingPredicate:predicate]; It works fine, but it's case-sensitive. I need the filtering should be case insensitive. I've tried, NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(ANY firstName CONTAINS %@ ) OR (ANY lastName

How to make a Global Array?

六月ゝ 毕业季﹏ 提交于 2019-12-06 02:40:44
问题 So, I read this post, and it's pretty much exactly what I was looking for. However... it doesn't work. I guess I'm not going to go with the singleton object, but rather making the array in either a Global.h file, or insert it into the _Prefix file. Both times I do that though, I get the error: Expected specifier-qualifier-list before 'static' and it doesn't work. So... I'm not sure how to get it to work, I can remove extern and it works, but I feel like I need that to make it a constant. The