nsarray

Swift - Insert object/item / Add object/item in NSArray

本小妞迷上赌 提交于 2019-12-04 05:13:49
I have this code: var NToDel:NSArray = [] var addInNToDelArray = "Test1 \ Test2" How to add addInNToDelArray in NToDel:NSArray ? You can't - NSArray is an immutable array, and as such once instantiated it cannot be changed. You should turn it into a NSMutableArray , and in that case it's as simple as: NToDel.addObject(addInNToDelArray) Alternatively, you can insert the value at instantiation time: var NToDel:NSMutableArray = [addInNToDelArray] but that's not about adding, it's about initializing - and in fact, after that line you cannot do any change to the array elements. Note that there's an

JSONModel returns nil

社会主义新天地 提交于 2019-12-04 04:53:52
问题 I'mm using JSONModel to get the JSON from the URL. It's a very simple object, containing only 2 strings - "name" and "url". First I made the Object Model: @protocol Tutorial @end @interface Tutorial : JSONModel @property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSString *url; @end Then Object Feed: #import "JSONModel.h" #import "Tutorial.h" @interface TutorialFeed : JSONModel @property (nonatomic, strong) NSArray <Tutorial> *tutorials; @end and then in

NSArray full of NSDictionaries. How to find index of object?

瘦欲@ 提交于 2019-12-04 04:52:59
I have an array which is filled with NSDictionaries . I want to find the index of one of the dictionary, but what I know about this dictionary is only a value for key @"name". How do I do it ? Find index of first dictionary in theArray whose value for @"name" is theValue : NSUInteger index = [theArray indexOfObjectPassingTest: ^BOOL(NSDictionary *dict, NSUInteger idx, BOOL *stop) { return [[dict objectForKey:@"name"] isEqual:theValue]; } ]; index will be NSNotFound if no matching object is found. NSArray *temp = [allList valueForKey:@"Name"]; NSInteger indexValue = [temp indexOfObject:YourText

Objective C Class or struct?

自闭症网瘾萝莉.ら 提交于 2019-12-04 04:48:13
I have a class Song with properties Title, Key, Artist, etc. There are no methods. I loop through a database of song information and create a Song object for each, populating the properties, and then store the Song objects in an NSArray. Then I thought, why not just have a struct Song with all those same properties instead of a class Song. Doing so would eliminate the class files, the #import Song line in the using class's .m file, and the need to alloc, init, release. On the other hand, I'd have to put the struct definition in every class that might need it. (Unless there's some globally

Strange behavoir when decoding an NSArray via NSSecureCoding

允我心安 提交于 2019-12-04 04:42:14
i spent all afternoon banging my head against the wall trying to figure out why decoding of this class was failing. the class has a property that is an NSArray of Foo objects. Foo conforms to NSSecureCoding, and i have successfully encoded and decoded that class by itself. i was getting an error in initWithCoder: that said failed to decode class Foo. through some experimentation, i discovered that i needed to add [Foo class] to initWithCoder: in order for it to work. maybe this will help someone else who's having the same problem. my question is, why is this necessary? i found no suggestion

Objective-C: How to find the most common string in an array?

你说的曾经没有我的故事 提交于 2019-12-04 04:40:18
问题 I have an array of strings from an online database that I trying to determine the most commonly used word. The values inside the arrays will vary but I want to check the most common words of whatever collection or words I'm using. If theoretically I had an array of the following... NSArray *stringArray = [NSArray arrayWithObjects:@"Duck", @"Duck", @"Duck", @"Duck", @"Goose"]; How do I iterate through this array to determine the most common string, which would obviously be "Duck"? 回答1:

Slice NSArray from end of array

点点圈 提交于 2019-12-04 04:26:43
What is the best way to "slice" an NSArray from the end, rather than the beginning, of the array (for example, finding the subarray containing the last few elements of a NSArray of unknown length)? In Python, you can use negative indices to accomplish this, e.g.: new_list = old_list[-5:-3] What's the most natural way to do this in Objective-C? There's nothing to match Python's nice syntax for this, but you could do: NSUInteger count = [myArray count]; NSArray * slice = [myArray subarrayWithRange:(NSRange){count-n, n}]; You could also write up a category for NSArray , something like: @interface

How to fill NSArray in compile time?

自古美人都是妖i 提交于 2019-12-04 03:36:27
问题 In Objective-C, how to do something like is int array[] = {1, 2, 3, 4}; in pure C? I need to fill NSArray with NSStrings with the smallest overhead (code and/or runtime) as possible. 回答1: It's not possible to create an array like you're doing at compile time. That's because it's not a "compile time constant." Instead, you can do something like: static NSArray *tArray = nil; -(void)viewDidLoad { [super viewDidLoad]; tArray = [NSArray arrayWithObjects:@"A", @"B", @"C", nil]; } If it's truly

Got a EXC_CORPSE_NOTIFY symbol crash, how to track it?

ⅰ亾dé卋堺 提交于 2019-12-04 03:01:56
问题 Here's the whole crash log. What's the meaning of EXC_CORPSE_NOTIFY exception notice? I have to replace some strings about our company. Incident Identifier: 40BD3A10-43A5-4F0D-A283-218E1D3BEE46 CrashReporter Key: 3d8d75a8f5eeb7c3d28d52883b92ed4e0fb2529e Hardware Model: iPhone7,1 Process: XxxxxXxxApp [13539] Path: /private/var/mobile/Containers/Bundle/Application/148C5049-8883-4E9D-BB98-5498EEA95191/XxxxxXxxApp.app/XxxxxXxxApp Identifier: com.Lotum.MCOLotumMobile Version: 7.0.8.0 (7.0.8) Code

Finding out NSArray/NSMutableArray changes' indices

泄露秘密 提交于 2019-12-04 01:09:34
问题 I have a NSMutableArray oldArray . Now, at one point, this NSMutableArray object gets updated with another NSMutableArray , which may have more, less or same number of elements as the previous NSMutableArray . I want to compare the old and the new array for changes. What I want are two NSArray s addedArray and removedArray which will contain the indices of the elements which have been added and/or removed from the old array. This whole problem will be more clear with an example : oldArray = {