IOS - Convert from NSSet to NSMutableSet [closed] - objective-c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Given an NSSet what is the best way to get an NSMutableSet with those same objects?
To be clear if you have an instance of NSSet what would be the most performant and simple way to get an NSMutable set with those same objects?

There are 2 ways to achieve it.
Use mutableCopy
Objective-C
NSMutableSet* mutableSet2 = [YOUR_SET mutableCopy];
Swift
let mutableSet = YOUR_SET.mutableCopy()
Use setWithSet:
Objective-C
NSMutableSet* mutableSet = [NSMutableSet setWithSet:YOUR_SET];
Swift
let mutableSet = NSMutableSet.init(set: YOUR_SET)

Related

How Do I Save an Integer After a Restart SpriteKit [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Simple as that, how do I save an Integer for score after the user has restarted the app. I'm trying to use SpriteKit for everything, so keep that in mind. I've tried NSUserDefaults but it doesn't seem to be working.
As msgambel points out below, you can save integers directly into NSUserDefaults via something like:
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:#"one"];
And separately, if you put an integer into a "NSNumber" object (i.e. an Objective C object), you can save these in NSUserDefaults or include these objects in arrays or dictionaries.
Check out [NSNumber numberWithInteger:]

How to name a selector which may generate an error? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am having trouble with naming my selector, which accepts a single parameter: a pointer to a pointer to an NSError instance. What is the best practice of doing that?
Right now I have something like:
- (void)loadContentIfNeededAndGenerateError:(NSError **)error;
But it doesn't look like a good way to name a selector.
Apple use the naming convention WithError:, so I guess:
- (BOOL)loadContentIfNeededWithError:(NSError **)error;
Note: Return BOOL and don't rely on the non-nil state of error in order to detect the error.
In other words:
NSError *error = nil;
if (![self loadContentIfNeededWithError:&error]) {
// React to error
}
Or just:
- (BOOL)loadContentIfNeeded:(NSError **)error;
I take my precedent from NSManagedObjectContext's:
- (BOOL)save:(NSError **)error;

How to change object in NSArray [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 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]]

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"];

what does this multi-dimensional array looking thing actually mean? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
#interface Foo {
Bar *bar[12][8][2];
}
And I am wondering what that means and what it is actually doing behind the scenes?
bar it is an array of 12 elements. Each element is an array of 8 elements, and each element is an array of 2 pointers to "Bar" objects.
No surprises -- It is a multi-demensional array of pointers to Bars.
In MRC, reference counts are managed manually.
In ARC, they are managed for you.