nsarray

Static NSArray of strings - how/where to initialize in a View Controller

南楼画角 提交于 2019-11-28 16:39:21
In a Master-Detail app I'd like to display a TableView with 5 sections titled: Your Move Their Move Won Games Lost Games Options So I create a blank Master-Detail app in Xcode 5.0.2 and then in its MasterViewController.m (which is a UITableViewController) I'm trying to implement the method: - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return _titles[section]; } My question is however how to init the NSArray _titles? I'm trying in the MasterViewController.m: #import "MasterViewController.h" #import "DetailViewController.h" static NSArray *_titles

Making an array of Objects in Objective-C.

若如初见. 提交于 2019-11-28 16:32:59
问题 Been playing around with XCode for about 2 weeks now, and reading about MVC a bit. I have a problem trying to connect the Model to the Controller because I find it hard to get my head around arrays. I can handle simple arrays when i programmed some in Java but I'm quiet intimidated by the Obj-C NSArrays I see. If somebody would be so kind to show me some simple calls on an array of objects i would be eternally grateful. My model: Person.h #import <Foundation/Foundation.h> @interface Person :

Join an Array in Objective-C

余生颓废 提交于 2019-11-28 16:26:32
I'm looking for a method of turning a NSMutableArray into a string. Is there anything on a par with this Ruby array method? >> array1 = [1, 2, 3] >> array1.join(',') => "1,2,3" Cheers! Jason Coco NSArray *array1 = [NSArray arrayWithObjects:@"1", @"2", @"3", nil]; NSString *joinedString = [array1 componentsJoinedByString:@","]; componentsJoinedByString: will join the components in the array by the specified string and return a string representation of the array. Rémy The method you are looking for is componentsJoinedByString . NSArray *a = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];/

Check if NSString instance is contained in an NSArray

只谈情不闲聊 提交于 2019-11-28 15:54:46
问题 I have an array with a bunch of strings and I want to check if a certain string is contained in the array. If I use the containsObject : message on the array, I'm getting correct results. Do all NSString objects with the same string point to the same object? Or why is the containsObject : working? NSArray *stringArray = [NSArray arrayWithObjects:@"1",@"2",@"3",anotherStringValue, nil]; if([stringArray containsObject:@"2"]){ //DO SOMETHING } 回答1: Yes, hard-coded NSStrings (string literals)

Finding maximum numeric value in NSArray

半腔热情 提交于 2019-11-28 15:31:22
I have an NSArray of NSNumbers and want to find the maximum value in the array. Is there any built in functionality for doing so? I am using iOS4 GM if that makes any difference. The KVC approach looks like this: int max = [[numbers valueForKeyPath:@"@max.intValue"] intValue]; or NSNumber * max = [numbers valueForKeyPath:@"@max.intValue"]; with numbers as an NSArray NSArray * test= @[@3, @67, @23, @67, @67]; int maximumValue = [[test valueForKeyPath: @"@max.self"] intValue]; NSLog(@" MaximumValue = %d", maximumValue); // Maximum = 67 Here is the swift version let maxValue = (numbers.value

Putting JSON into an Array

我的未来我决定 提交于 2019-11-28 14:40:46
I'm a noob when it comes to requests and JSON. Inside my app I send to the server and get back stuff so I can use it of course. I tried looking up different things but none really seem to be what I'm looking for. So I'm getting back what seems to be formatted JSON. What I want to know how to do is put it into a NSMutable array. The way I get this JSON is by using AFNetworking's AFJSONRequestOperation. My response looks like this. { id = 38; name = "St. Martin Hall"; }, { id = 40; name = "Assumptions Commons"; }, { id = 41; name = "Vickroy Hall"; }, { id = 42; name = "St. Ann Hall"; }, { id =

Filter NSArray of custom objects

好久不见. 提交于 2019-11-28 14:24:04
I have a NSArray of Contact objects, we can call it contacts . Contact is a superclass, FacebookGroup and Individual are subclasses of Contact . FacebookGroup has a property called individuals which is a set of Individual objects. I also have a NSArray of NSString objects, we can call it userIDs . What I want to do is create a new NSArray from the existing contacts array that match the userIDs in userIDs . So if contacts has 3 Contact objects with userID 1,2 and 3. And my userIDs has a NSString object 3. Then I want the resulting array to contain Contact which equals userID 3. Contact.h

how to resolve the issue: “'Instance method '-arrayByPerformingSelector:' not found (return type defaults to 'id')”

天大地大妈咪最大 提交于 2019-11-28 14:21:49
i saw in one post -(id)arrayByPerformingSelector declaration in interface should do , but when i tried it this declaration was treated as separate method and incomplete implementation issue came... sorry this is quite a silly doubt i am asking but I'm a newbie to iOS and wasn't able to find out whats wrong with this.. self.segmentedControl = [[UISegmentedControl alloc] initWithItems:[viewControllers arrayByPerformingSelector:@selector(title)]]; self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; and also when i run the project thread stops with SIGABRT and in console

Need to convert NSData to NSArray

佐手、 提交于 2019-11-28 14:14:57
I am pulling down a plist from a URL using an NSURLConnection, which returns an NSData object. I would like to convert this to an NSArray. Can anyone help me? I am refactoring a method that currently does a synchronous request to the URL, using arrayWithContentsOfURL: to get the NSArray. Thanks!! Use +[NSPropertyListSerialization dataWithPropertyList:format:options:error:] to convert the data, then check if the result -isKindOfClass:[NSArray class] . Use NSKeyedArchiver for archiving object to data. NSKeyedUnarchiver for unarchiving object from data: NSArray *object = [NSKeyedUnarchiver

Sorting NSArray containing NSDate objects

穿精又带淫゛_ 提交于 2019-11-28 13:57:34
I have an array containing NSDate objects. With Objective-C, I am able to sort this array by using: NSArray *array = [unsortedArray sortedArrayUsingSelector:@selector(compare:)] I'm wondering if there's a Swift equivalent of doing this same thing. Relatively new to Swift here, hacking my way through. Using the native Array type in Swift. If you are interfacing with legacy code from ObjC, use this: let array = unsortedArray.sortedArrayUsingSelector("compare:") If you use Swift array. let datesArray = [ NSDate(), NSDate(timeIntervalSinceNow: 60), NSDate(timeIntervalSinceNow: -60) ] let sorter: