2014-09-07 1 views
1

for 루프를 실행 중이며 키의 개체를 찾을 수 없습니다. 나는 그것이 어떤 다른 결과를했을 경우에보고 if 문에서 퍼팅 시도하고이 내 DescriptionDictionary (그것의 로그)Objectfor 키가 반환 될 때 null objectforkey가있을 때

{ 
    (
    "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(NSString *string in _titleArray) { 
    if([_descriptionDict objectForKey:string]) { 
     NSLog(@"YES"); 
    } else { 
     NSLog(@"NO"); 
    } 
} 
기록하지

편집 첫 번째 대답 덕분에 사전이 어떻게 된 것인지 알고 있으므로 질문은 계속됩니다. 나는 보통 사전에 그 설정하려면 어떻게

**********는 내가 대답에 따라 올바르게 형성하고 보인다 *********** 편집이 이 방법

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

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

를 형성하지만 난 여전히 그것은 원래 사전과 같은 동일한 방법으로

+0

NSLog를 읽는 법을 배웁니다. '{}'문자를 볼 때 사전을 의미하고'() '는 배열을 의미합니다. 따라서 위의 사전에는 모든 핵심 구문의 배열 인 키로 구성된 단일 항목이 있습니다. –

답변

2

을 기록으로 끝낼입니다 또 다른 큰 배열에 하나 개의 큰 배열의 매핑입니다. 사전이

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

처럼 설정해야합니다 그리고는 다음과 같이 기록합니다

{ 
key = object; 
otherKey = otherObject; 
} 

괄호는 매핑의 각 측면에 하나의 배열을 가지고 그것을 멀리 제공합니다.

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

당신이 무엇처럼 보이는이 같은 기록합니다

는이 같은 뭔가 더있다.

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

하면 배열 당신은 NSDictionary 클래스 메소드의 인수로 두 배열을 받아 제대로 다른 하나를 연결하는 사전을 구축 할 것입니다 [NSDictionary dictionaryWithObjects: forKeys:] 사용을 고려할 수 있습니다로 시작하는 이러한 데이터를 가져 오는 경우.

+0

이미 배열에있는 제목이 있기 때문에 둘을 구분하는 방법이 있습니까? – inVINCEable

+0

'[NSDictionary dictionaryWithObjects : objectArray for keys : keysArray]'는 잘 형성된 NSDictionary를 줄 것이다. – Fabian

+0

내 편집을 확인하십시오, 이미 사용 중입니다 – inVINCEable

관련 문제