当objectforkey存在时,Key返回Null的对象

时间:2014-09-07 23:06:39

标签: ios ios7 for-loop nsarray nsdictionary

我正在运行for循环,但找不到密钥的对象。我尝试输入一个if语句来查看它是否会有任何不同的结果并且它没有记录

这是我的DescriptionDictionary(它的日志)

{
    (
    "Apple's big event: Here's what to expect",
    "WeChat helps Apple rack up bonus points in China",
    "China Mobile Wants Apple's iPhone 6 to be a Blowout Success",
    "What Will Apple Announce On September 9th? Software and Hardware Predictions For The iPhone 6 Event",
    "Apple seeks old magic with new products",
    "Five ways Apple's iPhone 6, iWatch launches may transform its business model",
    "Apple's Plan To Kill PayPal Has Finally Become Clear (AAPL)",
    "Apple's mojo on the line at unveiling",
    "Will Apple",
    "Apple adds new Flyover Tours Before the Big Launch for iOS 8 and OS X Yosemite ",
    "Apple: watching for new directions",
    "Apple Looks to Fashion World for iWatch Rollout",
    "Apple website to live stream iPhone 6 launch event only for Apple devices",
    "Is Apple planning a catwalk show for its iPhone/iWatch event?"
) =     (
    "After months of anticipation, the tech industry event of 2014 is upon us: Apple's product launch day. The tech giant has said almost nothing publicly about what's in store Tuesday, but industry observers have some ideas. Apple (AAPL, Tech30) is widely ...",
    "BEIJING (Reuters) - Apple Inc has a lot for which to thank people like Deng. A Beijing-based quality analyst, she gave only her surname as she's embarrassed by how much money she spends playing mobile games on WeChat, a hugely popular messaging app ...",
    "Apple Store in Pudong Shanghai. Source: Apple. Earlier this week the world's largest mobile carrier, China Mobile (NYSE: CHL ) , launched a pre-order site for the new, not-yet-released Apple (NASDAQ: AAPL ) iPhones. It wasn't the first time the carrier has ...",
    "For fans and followers, journalists and analysts, to pop culture experts, celebrities, and late night chat show hosts, this Tuesday is going to be just like Christmas Day. While Apple has not said what will be announced at its September 9th event ...",
    "With its highly awaited product launch this week, Apple is aiming for a new ",
    "Apple is building a giant white cube outside of the Flint Center in Cupertino, CA. James Martin/CNET Apple's launch of the larger screen iPhone 6 and preview of iWatch or a similar wearable will aim to silence critics who contend the company's innovation ...",
    "Apple has been quietly putting together a plan to blow open the mobile-payments industry, making major deals with credit-card companies in a move that could threaten the dominance of PayPal and other mobile-payment companies. These deals could make Apple ...",
    "SAN FRANCISCO ",
    "Just this past week we released our tour of Motorola",
    "Apple knows they need to work on Maps. Improving their product started with faster turnarounds for updates and correcting errors and it continues with 3D flyover tours for more an more cities. A flyover tour will not make the Maps app more useful, but it ...",
    "San Francisco (AFP) - Apple's mystery unveiling on Tuesday is expected to be a watershed moment for the California giant -- and the entire tech industry. Here are key things to watch for: - Can Tim Cook step up? - Chief executive Tim Cook will seek to ...",
    "As intrigue builds around the mystery wearable product Apple is rumored to be launching next week, a new thread has been added to the story: high fashion. According to a new report, fashion journalists have been invited to Apple's Sept. 9 event, a move ...",
    "The Apple launch event is the most teased event for a while now, and this made the Apple to want every Apple users to watch the video by streaming the event on the Apple website. Apple wants each and everyone on this globe to watch the launch event of the ...",
    "There's a mysterious white building being built at the site of Apple's Tuesday event. Fashion bloggers have been invited. Ergo? Could there be a glorious catwalk lurking inside Apple's mystery cube? James Martin/CNET I took all my clothes to the dry ..."
);
}

这是我的一组密钥

"Apple's big event: Here's what to expect",
"WeChat helps Apple rack up bonus points in China",
"What Will Apple Announce On September 9th? Software and Hardware Predictions For The iPhone 6 Event",
"Apple's Plan To Kill PayPal Has Finally Become Clear (AAPL)",
"China Mobile Wants Apple's iPhone 6 to be a Blowout Success",
"Apple's mojo on the line at unveiling",
"Five ways Apple's iPhone 6, iWatch launches may transform its business model",
"Apple seeks old magic with new products",
"Apple: watching for new directions",
"Apple Looks to Fashion World for iWatch Rollout",
"Will Apple",
"Apple adds new Flyover Tours Before the Big Launch for iOS 8 and OS X Yosemite ",
"Is Apple planning a catwalk show for its iPhone/iWatch event?",
"Apple Hires Australia"

当我运行此for循环时,它总是不记录

for(NSString *string in _titleArray) {
    if([_descriptionDict objectForKey:string]) {
        NSLog(@"YES");
    } else {
        NSLog(@"NO");
    }
}

修改 由于第一个答案,知道字典是如何的,问题仍在继续。如何将其转换为普通字典

********** EDIT *********** 似乎我根据答案正确地形成了它们是如何形成的

    descForTitles = [NSDictionary dictionaryWithObject:descriptions forKey:titleArr];

    NSLog(@"Description Dict:%@", descForTitles);

但我仍然以相同的方式记录

1 个答案:

答案 0 :(得分:2)

看起来您的原始字典是一个大型数组到另一个大型数组的映射。字典应该像这样设置

@{@"key": @"object",
  @"otherKey": @"otherObject"};

它会像这样记录:

{
key = object;
otherKey = otherObject;
}

圆括号表示在映射的每一侧都有一个数组。

你有更像这样的东西:

@{@[@"key", @"otherKey"]:
  @[@"object", @"otherObject"]};

会像这样记录,看起来就像你拥有的那样。

{
(
    key,
    otherKey
) =     (
    object,
    otherObject
);
}

如果要将这些数据作为数组开始使用,您可以考虑使用NSDictionary类方法[NSDictionary dictionaryWithObjects: forKeys:],该方法将两个数组作为其参数,并将正确构建一个将一个数据与另一个相关联的字典