nsarray

What does a square-bracketed index after an NSArray mean? [duplicate]

半腔热情 提交于 2019-12-02 12:23:02
问题 This question already has answers here : What are the details of “Objective-C Literals” mentioned in the Xcode 4.4 release notes? (3 answers) Closed 5 years ago . Going through iTunes U Developing iOS 7 Apps for iPhone and iPad and in Lecture 3 slides, on page 120, there's a Quiz question that asks what the following line of code does. Frankly, I'm a bit stumped, and hoped someone could break it down. cardA.contents = @[cardB.contents,cardC.contents][[cardB match:@[cardC]] ? 1 : 0]; So, I get

convert NSArray of NSString(s) to NSArray of NSMutableString(s)

偶尔善良 提交于 2019-12-02 12:02:30
How to do that without having to "scroll" the entire given array with a "for" loop? Josh Caswell Since nobody seems to agree with my comment that this is a duplicate of Better way to convert NSArray of NSNumbers to array of NSStrings , here's the same answer again: NSArray * arrayOfMutableStrings = [arrayOfStrings valueForKey:@"mutableCopy"]; From the docs : valueForKey: Returns an array containing the results of invoking valueForKey: using key on each of the array's objects. - (id)valueForKey:(NSString *)key Parameters key The key to retrieve. Return Value The value of the retrieved key.

How to Covert struct with an Array of string to NSData and vice versa Swift

旧时模样 提交于 2019-12-02 09:51:51
I have this struct: struct MessageRandomWords { let message = MessageType.kMessageTypeRandomWords let randomWords : Array<Array<String>> } I'm trying to convert this struct to NSDate by doing this: var message = MessageRandomWords(randomWords: self.words) let data = NSData(bytes: &message, length: sizeof(MessageRandomWords)) But when i'm trying to convert this back to the original struct: var messageRandomWords : MessageRandomWords? data.getBytes(&messageRandomWords, length: sizeof(MessageRandomWords)) if let messageRandomWords = messageRandomWords { } I got a BAD_ACCESS erro on the if let

Difference between literals and class methods for NSMutableArray and NSMutableDictionary [duplicate]

孤者浪人 提交于 2019-12-02 09:49:26
问题 This question already has an answer here : Is literal creation of an NSMutableDictionary less efficient than the class helper method? (1 answer) Closed 6 years ago . When I started with OSX/iOS I used NSMutableArray * a1 = [NSMutableArray arrayWithCapacity:123] ; NSMutableDictionary * d1 = [NSMutableDictionary dictionaryWithCapacity:123] ; Then I discovered the 'simpler' version NSMutableArray * a2 = [NSMutableArray array] ; NSMutableDictionary * d2 = [NSMutableDictionary dictionary] ; I have

Parsing Json to get all the contents in one NSArray

a 夏天 提交于 2019-12-02 09:16:37
That's the content... [ { "id": "", "title": "", "website": "", "categories": [ { "id": "", "label": "" } ], "updated": }, { "id": "", "title": "", "website": "", "categories": [ { "id": "", "label": "" } ], "updated": } ] How can I insert every feed source in one array? NSDictionary *results = [string JSONValue]; NSArray *subs = [results valueForKey:@"KEY"]; Which key I must insert? THanks as I can see your structure, you will get out of this JSON-String NSArray: [ NSDictionary: { NSString: "id", NSString: "title", NSString: "website", NSArray: "categories": [ NSDictionary: { NSString: "id",

Sorting an NSArray by a key-value relationship that is 2 levels deep

两盒软妹~` 提交于 2019-12-02 09:15:39
I have an NSArray of UILocalNotification objects that I need to sort according to a key within the UILocalNotification's userInfo property, which is an NSDictionary. I know how to sort NSArrays by a value that is one level deep, e.g., a key within an array of NSDictionaries, but two levels deep I'm lost. I want to do something like this is psuedo-code: NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"userInfo.personName" ascending:YES]; //the personName key within the userInfo NSDictionary property of a given UILocalNotification NSArray *sortDescriptors = [[[NSArray

NSArray Tokenize on base of a key

南楼画角 提交于 2019-12-02 08:30:41
I have already fetched data from server and passing the data is also populated with NSMutableArray after NSJSONSerialization . Output of array is as follow's: NSArray *jsonArray = (NSArray *)json; NSLog(@"Array - %@",jsonArray); I want to create a new array which will contain all the data of newsletter. Array - ( { error = 0; newsletter = ( { date = "2015-11-23"; description = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it

Turning an NSArray of custom objects into a alphabetically sectioned UITableView with an index?

微笑、不失礼 提交于 2019-12-02 08:16:05
(hmm.. long title) If I start out with an NSArray of custom objects (each object is a Person) like this: { surname:Allen forename: Woody, surname:Baxter forename: Stanley, surname:Clay forename: Cassius } ..etc.. You can see that the array is already in surname order. How do I use that array to create a a UITableView with a section headers A, B C etc, as well as an index thing on the side running vertically A B C EDIT I guess what I'm asking is how to turn my array of objects into a Section Array, with all the first letters of the Surnames, and a Surname Array which is perhaps a nested array

Case insensitive indexOfObject for NSArray

非 Y 不嫁゛ 提交于 2019-12-02 06:31:08
问题 Is there an easy way to do a case insensitive lookup in an NSArray of NSStrings? Reference for NSArray mentions sorting case insensitively but nothing about lookup. I can easily write my own fn to do it but would like to know if there's an easier way. 回答1: I don't know of any built-in way to do this. However, it would be trivial to write a category on NSArray which does this: @interface NSArray (CaseInsensitiveIndexing) - (NSUInteger)indexOfCaseInsensitiveString:(NSString *)aString; @end

What does a square-bracketed index after an NSArray mean? [duplicate]

梦想的初衷 提交于 2019-12-02 04:50:49
This question already has an answer here: What are the details of “Objective-C Literals” mentioned in the Xcode 4.4 release notes? 3 answers Going through iTunes U Developing iOS 7 Apps for iPhone and iPad and in Lecture 3 slides, on page 120, there's a Quiz question that asks what the following line of code does. Frankly, I'm a bit stumped, and hoped someone could break it down. cardA.contents = @[cardB.contents,cardC.contents][[cardB match:@[cardC]] ? 1 : 0]; So, I get the first part, cardA.contents = a new array with cardB.contents and cardC.contents in the array. But, next comes (I guess??