nsarray

Creating a NSArray from a C Array

感情迁移 提交于 2019-12-05 17:39:09
There are many threads about going the opposite way, but I am interested in converting from a primitive C array to a NSArray. The reason for this is that I want to create a NSString from the array contents. To create the NSString I will use: NSArray *array; NSString *stringFromArray = [array componentsJoinedByString:@","]; I am joining the elements of the array by commas because I will later be saving the string as a .csv file. I don't think it matters, but the C array I am dealing with is of type double and size 43. double c_array = new double [43]; Thanks! NSString * stringFromArray = NULL;

Method swizzling for NSArray

不打扰是莪最后的温柔 提交于 2019-12-05 16:52:45
I'm trying to debug something on an NSArray and I can't even find what the pointer to the array that's causing the issue is and I have no idea why it's happening. I'm getting an error on objectAtIndex: (out of bounds) and it seems to be coming from some internal NSView method... anyway, I tried swizzling objectAtIndex: with my own, but it won't work. What's strange is I can do the same thing but with another class and method, and it works fine. Here's what I'm doing to swizzle: Class arrayClass = [NSArray class]; Method originalMethod = class_getClassMethod(arrayClass, @selector(objectAtIndex:

How to convert Data of Int16 audio samples to array of float audio samples

心不动则不痛 提交于 2019-12-05 16:17:43
I'm currently working with audio samples. I get them from AVAssetReader and have a CMSampleBuffer with something like this: guard let sampleBuffer = readerOutput.copyNextSampleBuffer() else { guard reader.status == .completed else { return nil } // Completed // samples is an array of Int16 let samples = sampleData.withUnsafeBytes { Array(UnsafeBufferPointer<Int16>( start: $0, count: sampleData.count / MemoryLayout<Int16>.size)) } // The only way I found to convert [Int16] -> [Float]... return samples.map { Float($0) / Float(Int16.max)} } guard let blockBuffer = CMSampleBufferGetDataBuffer

Save Array to plist

烂漫一生 提交于 2019-12-05 16:09:17
I'm trying to store some items into a pList . Here is the array loop: for (id obj in items) NSLog(@"obj: %@", obj); Output NSLog: 2013-03-27 13:00:40.072 mycode[47436:c07] obj: Red 2013-03-27 13:00:40.073 mycode[47436:c07] obj: Blue 2013-03-27 13:00:40.073 mycode[47436:c07] obj: Green // The arrayWithObjects works. But I don't know how to (loop?) through my items for saving into the plist file... NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory

NSDictionary's allKeys array messed up - not in the order they are in the dictionary?

烂漫一生 提交于 2019-12-05 11:26:04
in my project I'm pulling data from a .plist, more concretely from an NSDictionary. I init a dictionary with the contents of the .plist, which works well. When I then do NSArray *array = [dict allKeys]; it fills the array with all the keys, but in a totally random order, different to the order they are in the .plist file. I would really need to preserve the order. The keys in the dictionary are arrays, if that could cause a problem. What am I not getting? Thanks a lot in advance! Much like there is no order between items in an NSSet, there's is no inherent order to the key-value pairs within

How can i convert a NSData to NSArray? [duplicate]

删除回忆录丶 提交于 2019-12-05 10:56:41
问题 This question already has answers here : Closed 8 years ago . Possible Duplicates: How to convert NSArray to NSData? Need to convert NSData to NSArray HI, I have a NSData object named as "myNsData"(it is converted form of NSArray) and a NSarray named as "myNsArray. can any one provide me a code to convert a NSData to NSArray? 回答1: See this post... Convert NSArray to NSData The last comment deals with the reverse.... NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:data] 回答2: I am

extracting properties from NSArray of objects

只谈情不闲聊 提交于 2019-12-05 10:27:10
问题 Is there any of way (other than looping) of extracting a particular property of all objects in an array. So say there in an array of people. I want to extract all their first names into an array. 回答1: Key Value coding will help you with that: NSArray *result = [people valueForKey:@"firstname"]; 回答2: I got answer for my question. This is how we can achieve the same in swift. let arraytWithProperties = arrayWithObjects.map{ $0.propertyName } 来源: https://stackoverflow.com/questions/12312032

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

How to convert a JSON String into an NSArray? [closed]

风格不统一 提交于 2019-12-05 09:53:02
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am facing an issue while converting an NSString to NSArray. My string is : ["Default", "Discipleship", "Faith", "Family", "Hope", "Life Building", "Love", "Missions", "Relationships"] What i want to do is get the elements(Default,Discipleship etc.) out of this string and put them into an NSArray. I have tried a lot but couldn't get it done, please help Any help would be great , thanks in advance First you

NSString from NSArray

妖精的绣舞 提交于 2019-12-05 09:03:06
I am trying to create a String from Array.But, there is condition to how it should be generated, as explained below. NSArray *array=[NSArray arrayWithObjects:@"Hello",@"World",nil]; [array componentsJoinedByString:@","]; This will output: Hello,World. But, if first Item is Empty,then is there way to receive the only second one. Hello , @"" => Hello @"" , World => World Hello , World => Hello,World Alladinian Another way to do this is to grab a mutable copy of the array and just remove non valid objects. Something like this perhaps: NSMutableArray *array = [[NSArray arrayWithObjects:@"",@"World