Post

Replies

Boosts

Views

Activity

Reply to Swift block added in Dictionary is giving Nil in Objective C
Sample Code.Objective C Methods-(void)workingCodeMethod:(void (^)(void))completionHandler { if (completionHandler) { completionHandler(); }}-(void)crashCodeMethod:(NSDictionary *)loginData { void (^completionHandler)(void) = [loginData objectForKey:@"callback"]; if (completionHandler) { completionHandler(); }}Swift Methods @IBAction func workingCodeAction(_ sender: Any) { // Block in Dictionary is passed to Objective C class. viewController?.crashCodeMethod(getAuthorizationData()) } @IBAction func crashCodeAction(_ sender: Any) { viewController?.workingCodeMethod({ print("Its working") }) }// Block is added in Dictionary. private func getAuthorizationData() -> [String: Any] { var data: [String: AnyObject] = [String: AnyObject]() data["callback"] = { print("Its crashing") } as AnyObject return data }
Jan ’20