I have a for-loop. Inside that loop I want to fill up an NSArray with some objects. But I dont see any method that would let me do that. I know in advance how many objects there are. I want to avoid an NSMutableArray, since some people told me that's a very big overhead and performance-brake compared to NSArray.
I've got something like...
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!
...
Probably I could create a class that holds an CGPoint as instance variable, like a wrapper. Does that make sense? I feel uncomfortable with that, though. I hope there is an better solution.
How about any self-created scalar type? Like MyCoolScalarType?
...
NSArray has useful methods to find objects for specified indexes
// To find objects by indexes
- (id)objectAtIndex:(NSUInteger)index
- (NSArray *)objectsAtIndexes:(NSIndexSet *)indexes
// To find index by object
- (NSUInteger)indexOfObject:(id)anObject
However, I want to get NSIndexSet (multiple indexes) for given objects. Something ...
Hey,
I have an method that reads an xml file and stores the xml nodes at a certain XPath-path in an NSArray called *nodes. What I want to do is take each one of the items in the array and add it to a core data entity called Category with the attribute of "name".
I have tried a number of different ways of creating the entity but I'm no...
I'm looking for the standard idiom to iterate over an NSArray. My code needs to be suitable for OS X 10.4+.
...
NSDictionary is good for key-value pairs, by what data structure is best for when you have three values? Is is best to create a class for those 3 values, and then let each object in an array contain instances of that class?
To be specific: The data structure, let's call it Person, I envisage has three values:
(NSString)name, (int)age, ...
A UIActionSheet is initalized with:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
otherButtonTitles:@"Button1", @"Button2", nil];
I am trying to pass an NSArray into the "otherButtonTitles" message.
I tried to pass an NSArray using:
...
I have some code which needs to access a NSArray to work. I have a NSArray which I am using with core data and will have data in it. But i am unsure how to make it access the NSArray.
I can't just simply declare it in the Header file like this: NSArray *objectArray; because it does not know how or which NSArray to Access. How exactly wou...
I'm using json-framework to create a NSDictionary out of a JSON response. That much works wonderfully.
Now, within this JSON payload are one or more objects - let's call them X. Sort of like this in XML:
<OBJECTS>
<X>
...
</x>
<X>
...
</X>
<X>
...
</X>
</OBJECTS>
When I look in the aforementioned NSDictionary ...
I have a Dictionary of Dictionaries which is being returned to me in JSON format
{
"neverstart": {
"color": 0,
"count": 0,
"uid": 32387,
"id": 73129,
"name": "neverstart"
},
"dev": {
"color": 0,
"count": 1,
"uid": 32387,
"id": 72778,
"name": "dev"
},
"iphone...
Is there any way to create a new
NSString from a format string like @"xxx=%@, yyy=%@" and a NSArray of objects?
In the NSSTring class there are many methods like:
- (id)initWithFormat:(NSString *)format arguments:(va_list)argList
- (id)initWithFormat:(NSString *)format locale:(id)locale arguments:(va_list)argList
+ (id)stringWithForma...
I want to create an NSArray with objects of the same value (say NSNumber all initialized to 1) but the count is based on another variable. There doesn't seem to be a way to do this with any of the intializers for NSArray except for one that deals with C-style array.
Any idea if there is a short way to do this?
This is what I am lookin...
My question is why does it output the last 4 lines in the log(see below)...those objects are part of the dictionary printed earlier in the log & should not be located at the end of the array? I am missing something fundamental here... thx
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[NSURL URLWithString: @"www...
In Objective-C, if array1 is copied onto array2 using mutableCopy, and suppose the code is done in main(), who is responsible for releasing the objects contained in the array? Is it main() or array2?
...
NSIndexPath* updatedPath = [NSIndexPath indexPathForRow: 0 inSection: 0];
NSIndexPath* updatedPath2 = [NSIndexPath indexPathForRow: 1 inSection: 0];
NSArray* updatedPaths = [NSArray arrayWithObjects:updatedPath, updatedPath2, nil];
[self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];
...
When I was using an NSArray, it was easy:
NSArray *array = ...
lastIndex = INT_MAX;
...
int randomIndex;
do {
randomIndex = RANDOM_INT(0, [array count] - 1);
} while (randomIndex == lastIndex);
NSLog(@"%@", [array objectAtIndex:randomIndex]);
lastIndex = randomIndex;
I need to keep track of the lastIndex because I want the feeling o...
I have an NSArray that contains date strings like this: "Thu, 21 May 09 19:10:09 -0700"
I need to sort the NSArray by date. I thought about converting the date string to an NSDate object first, but got stuck there on how to sort by the NSDate object.
Thanks.
...
I have two arrays in Objective C and I need to find what index something is so I can insert it in the same place. For instance, lets say I have a "name array" and an "age array". How do I find out what index "charlie" is in the "name array" so I know where to insert his age in the "age" array?
Thanks
...
An iPhone question for you guys! I have an NSURLConnection that downloads XML from a server and processes it into an array which is a part of another array. I have no way of knowing how many objects I will need, so I cannot allocate an NSArray beforehand. My question is:
Would it be better to create the parent array as an NSArray at the...