How to change object in NSArray [closed] - objective-c

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have two NSArrays and I would like to change one object in the first NSArray with another object in the second NSArray.
This is what I tried to do, but with no luck:
[[arrrndwords objectsinindex:i] replace object in index:1 with:[arrword indexinobject:rndnum]];
It throws me out of the app when I run it.

The method you are looking for is:
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects
but it is not available to NSArray because it's immutable, you should use a NSMutableArray.
[array replaceObjectsAtIndex:[NSIndexSet indexSetWithIndex:1] withObjects:[NSArray arrayWithObject:yourObject]]

Related

MapView snippet objective c dot notation vs message passing notation? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I saw quite a few examples with maps around the net with
MapView.showsUserLocation=TRUE;
What would be the corresponding equivalent with message passing notation?
That depends on the property declaration. In the standard case when no custom setter is declared it is:
[mapView setShowsUserLocation:TRUE];
Note that you probably want YES instead of TRUE.

NSColorWeel in objective-c.... how does it works? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
That's the problem: I have to take an NSColor from the colorweel... how could I do? I tried declaring
NSColorWeel *weel;
But I don't know what to do next!
You could go read the docs?
Looks like you just call
- (NSColor *)color
to get the current color of the well, and
- (void)activate:(BOOL)exclusive
to activate it.

get and remove the object in nsmutablearray at specific index [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want the name of method of nsmutablearray which return the object at the given index and then remove this object from index and then sort the array accordingly.
Well, you're looking for two different things. To retrieve the object at a specific index in an array, you use -[NSMutableArray objectAtIndex:]. To remove an object at a specific index you use -[NSMutableArray removeObjectAtIndex:].

NSString get file as string by removing path [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
If i have a string like /Users/me/Documents/code/maccode/myApp/Icon.png
what should I do to be left only with "Icon.png"?
Using xcode and programming a mac application with objective c.
Thanks in advance.
NSString *filename = #"/Users/me/Documents/code/maccode/myApp/Icon.png";
NSString *path = [filename lastPathComponent];
That will give you Icon.png

How to add an NSMutableArray into NSMutableDictionary as a key? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have an array storing some attributes (those attributes are: tableID(string), tables coordinate(x,y coordinate in float)). Does anyone know how to store this array into NSMutableDictionary? And I need this NSMutableDictionary transfer into JSON string.
You can Simply set ur MUtable Array in MUtable Dictionary like
NSMutableDictionary *muteDict = [[NSMutableDictionary alloc] init];
[muteDict setObject:mutableArrayObject forKey:#"YourKey"];