Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
iOS Development
About the questions of NSDictionary
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="copperybean" data-source="post: 1409600" data-attributes="member: 254454"><p>I am using NSDictionay, but some questions really puzzled me.</p><p>Following is the related code</p><p></p><p>[CODE]</p><p>@interface AttributedStringDoc : NSObject {</p><p> // ....... other properties</p><p></p><p>@private </p><p> // ..... other privates</p><p> NSDictionary *pageRangesInfo;</p><p>}</p><p>@end</p><p></p><p></p><p></p><p>@implementation AttributedStringDoc</p><p></p><p>// ....... other function's implementation</p><p></p><p>// this function is called by the init*** function</p><p>- (void)loadWithFileName {</p><p></p><p> // ....... other codes</p><p></p><p> pageRangesInfo = [[NSDictionary alloc] initWithContentsOfFile:filePath];</p><p></p><p> // .........other codes</p><p>}</p><p></p><p></p><p>-(NSDictionary *)rangeInfoForPage:(NSInteger)pageNumber {</p><p> return [pageRangesInfo objectForKey:[NSString stringWithFormat:@"%d", pageNumber]];</p><p>}</p><p>@end</p><p>[/CODE]</p><p></p><p></p><p>The main content of file used to to be parsed by NSDictionary is formed like following:[CODE]</p><p><key>0</key></p><p><dict></p><p> <key>ASD_RANGE_END_INDEX</key></p><p> <integer>1256</integer></p><p><dict></p><p><key>1</key></p><p><dict></p><p> <key>ASD_RANGE_END_INDEX</key></p><p> <integer>5464</integer></p><p><dict></p><p>[/CODE]</p><p></p><p>The function rangeInfoForPage will be called several time. After called some times, the program will crash. But if I only return nil in function rangeInfoForPage, then every thing is OK. And I debugged the program also, I found function rangeInfoForPage can return correct value for some first steps.</p><p></p><p>So, I am wondering whether I am not using NSDictionary correctly?</p><p>Could any one help me, I am studying iOS programming by myself, and I'm really blocked by this!</p></blockquote><p></p>
[QUOTE="copperybean, post: 1409600, member: 254454"] I am using NSDictionay, but some questions really puzzled me. Following is the related code [CODE] @interface AttributedStringDoc : NSObject { // ....... other properties @private // ..... other privates NSDictionary *pageRangesInfo; } @end @implementation AttributedStringDoc // ....... other function's implementation // this function is called by the init*** function - (void)loadWithFileName { // ....... other codes pageRangesInfo = [[NSDictionary alloc] initWithContentsOfFile:filePath]; // .........other codes } -(NSDictionary *)rangeInfoForPage:(NSInteger)pageNumber { return [pageRangesInfo objectForKey:[NSString stringWithFormat:@"%d", pageNumber]]; } @end [/CODE] The main content of file used to to be parsed by NSDictionary is formed like following:[CODE] <key>0</key> <dict> <key>ASD_RANGE_END_INDEX</key> <integer>1256</integer> <dict> <key>1</key> <dict> <key>ASD_RANGE_END_INDEX</key> <integer>5464</integer> <dict> [/CODE] The function rangeInfoForPage will be called several time. After called some times, the program will crash. But if I only return nil in function rangeInfoForPage, then every thing is OK. And I debugged the program also, I found function rangeInfoForPage can return correct value for some first steps. So, I am wondering whether I am not using NSDictionary correctly? Could any one help me, I am studying iOS programming by myself, and I'm really blocked by this! [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
iOS Development
About the questions of NSDictionary
Top