nsmutablearray

Change a value within a NSMutableArray

独自空忆成欢 提交于 2019-12-05 12:05:25
I have a NSMutableArray that is loaded with values. Later in the application, I need to change the values of one of the elements in the array. How do I accomplish this? thanks tony Take a look at the class reference instance methods: http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Classes/NSMutableArray_Class/Reference/Reference.html You can use: replaceObjectAtIndex:withObject: given you know the index of the object. replaceObjectsAtIndexes:withObjects: to replace multiple objects at once. Call -[NSMutableArray replaceObjectAtIndex:withObject:] . Or, if the

Fast Enumeration With an NSMutableArray that holds an NSDictionary

蹲街弑〆低调 提交于 2019-12-05 11:02:50
Is it possible to use fast enumeration with an NSArray that contains an NSDictionary? I'm running through some Objective C tutorials, and the following code kicks the console into GDB mode NSMutableArray *myObjects = [NSMutableArray array]; NSArray *theObjects = [NSArray arrayWithObjects:@"easy as 1",@"easy as two", @"Easy as Three"]; NSArray *theKeys = [NSArray arrayWithObjects:@"A",@"B",@"C"]; NSDictionary *theDict = [NSDictionary dictionaryWithObjects:theObjects forKeys:theKeys]; [myObjects addObject:theDict]; for(id item in myObjects) { NSLog(@"Found an Item: %@",item); } If I replace the

How can I convert NSMutableArray into NSString?

风格不统一 提交于 2019-12-05 09:56:08
I am trying to convert (or copy?) a NSMutableArray into a NSString . I guess my problem is that I don't really understand the structure of a NSString . After conversion I want to attached it in email body. Here is my code: - (IBAction)sendEmail { NSLog(@"sendEmail"); [textView resignFirstResponder]; [textView1 resignFirstResponder]; if ([MFMailComposeViewController canSendMail]) { // set the sendTo address NSMutableArray *recipients = [[NSMutableArray alloc] initWithCapacity:1]; [recipients addObject:@"example@yahoo.com"]; MFMailComposeViewController *controller = [[MFMailComposeViewController

Selectively remove and delete objects from a NSMutableArray in Swift

Deadly 提交于 2019-12-05 09:22:09
Basic question. What is the best way to selectively remove and delete items from a mutable Array in Swift? There are options that do NOT seem to be suited for this like calling removeObject inside a for in loop enumeration block and others that appear to work in general like for loop using an index + calling removeObjectAtIndex , even inside the loop for in loop for populating an arrayWithItemsToRemove and then use originalArray. removeObjectsInArray(arrayWithItemsToRemove) using .filter to create a new array seems to be really nice, but I am not quite sure how I feel about replacing the whole

I'm trying to get a UILabel to scroll inside of a UIScrollView but it doesnt scroll

人走茶凉 提交于 2019-12-05 08:49:04
This is in my .m - (void)viewDidLoad { [super viewDidLoad]; [self.scrollView addSubview:self.contentView]; self.scrollView.contentSize = self.contentView.bounds.size; NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; NSMutableArray *arr = [[NSMutableArray alloc]init]; arr = [Singleton getArray]; NSString *str = [arr componentsJoinedByString:@"\n"]; summaryLabel.text = str; } This is in my .h @interface TotalViewController : UIViewController { UIScrollView *scrollView; UIView *contentView; } @property (nonatomic, retain) IBOutlet UIScrollView * scrollView; @property

NSKeyedArchiver archivedDataWithRootObject:

妖精的绣舞 提交于 2019-12-05 08:07:49
Is the parameter for NSKeyedArchiver archivedDataWithRootObject: supposed to be the array I am trying to save, or the array converted into NSData? To convert a generic array to an NSData , you need an archiver! If you know how to feed the NSData , you know how to use NSKeyedArchiver . So: NSArray* array= ... ; NSData* data=[NSKeyedArchiver archivedDataWithRootObject:array]; Of course all elements in your array needs to implement encodeWithCoder: . Bruce Lee Yuji's answer is right. but more accurately, your element of an array have to implement protocol and fillin your own code to methods

Adding objects to a NSMutableArray property

风流意气都作罢 提交于 2019-12-05 07:55:50
this is my data strucure: group [1...n] { id, name, elements : [1...n] } I define a class for element with all properties and a class for group as: @interface Group : NSObject { NSInteger groupID; NSString *groupName; NSMutableArray *elements; } @property (assign, readwrite) NSInteger groupID; @property (assign, readwrite) NSString *groupName; @property (assign, readwrite) NSMutableArray *elements; and single element with: @interface Element : NSObject { NSInteger elementID; NSString *elementName; } @property (assign, readwrite) NSInteger elementID; @property (assign, readwrite) NSString

Two Dimension NSMutableArray help?

三世轮回 提交于 2019-12-05 07:42:11
问题 Ok, I have some C# code that looks like this and I was wondering what other developers would recommend if I am trying to put this into Objective-C. List<List<string>> meta_data I'm planning on using NSMutableArray but how to exactly get that two-dimensional array figured out is my problem, since there is no such thing as a multidimensional array in Objective-C. I'm new to using NSMutableArray , so I still need some help every now and then. I know I will just add string objects to the array

Multiple Arrays From Plist

余生颓废 提交于 2019-12-05 07:14:44
问题 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <array> <array> <string>Title 1</string> <string>Subtitle 1</string> <string>image1.png</string> </array> <array> <string>Title 2</string> <string>Subtitle 2</string> <string>image2.png</string> </array> </array> </plist> This is my Plist file for an app I am working on. I am not sure on how to take the first string of many arrays

Removing last object in NSMutablearray [closed]

大憨熊 提交于 2019-12-05 06:20:47
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center . Closed 7 years ago . Is there any why to remove last object in NSMutablearray without crashing app? :D Sure: send the removeLastObject message to a valid NSMutableArray object which is not empty. 来源: https://stackoverflow.com/questions/13498707/removing-last-object-in