Câu hỏi phỏng vấn Objective-C
Câu hỏi

What are blocks and how are they used?

Câu trả lời

Blocks in Objective-C

Blocks in Objective-C are a language feature that allow you to create self-contained units of functionality that can be passed as arguments to methods or functions, or stored in variables. They are similar to closures in other programming languages.

Key characteristics of blocks:

  1. Encapsulate code: Blocks allow you to encapsulate a piece of code that can be executed later.
  2. Capture variables: Blocks can capture variables from their surrounding context, allowing them to access and modify those variables.
  3. First-class citizens: Blocks are first-class citizens, meaning they can be assigned to variables, passed as arguments to functions or methods, and returned from functions or methods.

How blocks are used:

  1. Callbacks: Blocks are commonly used as callbacks, where a block is passed as an argument to a method or function and is executed when a certain event occurs.

  2. Sorting and filtering: Blocks are used with methods like sortUsingBlock: and filteredArrayUsingPredicate: to provide custom sorting and filtering logic.

  3. Asynchronous operations: Blocks are used with asynchronous operations...

junior

junior

Gợi ý câu hỏi phỏng vấn

senior

How to create an abstract class in Objective-C?

middle

What is the purpose of managed object context NSManagedObjectContext in Objective-C and how does it work?

entry

Name four important data types found in Objective-C

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào