NIRMAL

NIRMAL

@EnvironmentObject in SwiftUI

The @EnvironmentObject property wrapper in SwiftUI is a powerful mechanism for dependency injection that allows you to share data between views without explicitly passing it through initializers. What is @EnvironmentObject? @EnvironmentObject is a property wrapper that provides access to shared objects living in the SwiftUI…

What is @ObservableObject in SwiftUI

After talking about @Observable so much, I realize I should properly explain @ObservableObject, the pattern I lived with for years before Apple introduced the newer macro. Even though @Observable is the future, understanding @ObservableObject is still crucial since it’s what powers most existing SwiftUI apps and will…

Understanding @Binding in SwiftUI

When I first started building SwiftUI apps, I was constantly running into situations where I needed different parts of my interface to talk to each other. That’s when I discovered @Binding, and honestly, it was a game-changer for how I think…

Difference Between NSArray and NSMutableArray

When I’m working on iOS projects using Objective-C, I frequently need to work with collections of objects. Apple gives us two main array classes: NSArray and NSMutableArray. While they’re closely related, understanding their differences has been crucial for writing effective code. NSArray: NSArray is…

Difference between print() and debugprint()

In iOS Swift development, both print() and debugPrint() are used to output information to the console, but they serve different purposes and provide different levels of detail. Key Differences: print() Function print() writes the textual representations of the given items into the standard output. It…

Category and Class Extension in Objective C

1. Category  Category in Objective-C allows you to add new methods (instance and class methods) to an existing class, even if you don’t have the source code for that class. Categories provide a powerful way to extend the behavior of system or third-party…

Explain Property Attributes in Objective C

1. assign Difficulty: Using assign for objects can cause dangling pointers if the assigned object is deallocated. If subtitle is deallocated elsewhere, this property will point to invalid memory, leading to a crash. 2. strong ARC Behavior: Difficulty: Can cause…

Atomic and nonatomic Properties in Objective-C

Objective-C properties can be declared as either atomic (the default) or nonatomic. Understanding the distinction is critical, especially for multithreading and performance implications in iOS/macOS development. Atomic Example: Nonatomic Example: Key Points: In summary:Use atomic only if you have a very specific need for atomicity in…

What is @State in SwiftUI?

@State is a property wrapper used to declare state variables in a view. When the state changes, SwiftUI automatically re-renders the parts of the view affected by that state. It is suitable for simple, local state management within a view. The @State property…

Dependency injection in swift

It is a design pattern used to achieve loose coupling, modularity, and better testability in your code. Instead of letting a class or struct create its own dependencies, you provide or inject those dependencies from the outside—usually at initialisation, through…