How can I convert an NSArray
to an NSDictionary
, using an int field of the array's objects as key for the NSDictionary
?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- back button text does not change
相关文章
- 现在使用swift开发ios应用好还是swift?
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
This adds a category extension to
NSArray
. NeedsC99
mode (which is the default these days, but just in case).In a
.h
file somewhere that can be#import
ed by all..In a
.m
file..Example use:
Outputs:
This is an example of creating a
NSMutableDictionary
from the employee listNSMutableArray
:Try this magic:
FYI this is possible because of this built-in feature:
I have created a simple library, called Linq to ObjectiveC, which is a collection of methods that makes this kind of problem much easier to solve. In your case you need the Linq-to-ObjectiveC toDictionary method, where your 'int' field is specified via a key selector:
This returns a dictionary where the keys are given by the
intField
in the source array.