Counter and Theme Toggle - Objective-c Typing CST Test
Loading…
Counter and Theme Toggle — Objective-c Code
Demonstrates a simple counter with theme toggling using Objective-C console output (can be adapted for iOS apps).
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
int count = 0;
BOOL isDark = NO;
void (^updateUI)(void) = ^{
NSLog(@"Counter: %d", count);
NSLog(@"Theme: %@", isDark ? @"Dark" : @"Light");
};
void (^increment)(void) = ^{ count++; updateUI(); };
void (^decrement)(void) = ^{ count--; updateUI(); };
void (^reset)(void) = ^{ count = 0; updateUI(); };
void (^toggleTheme)(void) = ^{ isDark = !isDark; updateUI(); };
// Simulate actions
updateUI();
increment();
increment();
toggleTheme();
decrement();
reset();
}
return 0;
}Objective-c Language Guide
Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to C. It has been the primary language for macOS and iOS development before Swift, enabling developers to create applications for Apple platforms with dynamic runtime capabilities.
Primary Use Cases
- ▸macOS and iOS application development
- ▸Legacy Apple framework integration
- ▸Developing Cocoa and Cocoa Touch applications
- ▸Creating reusable Objective-C libraries
- ▸High-performance system-level Apple apps
Notable Features
- ▸Object-oriented with classes and categories
- ▸Dynamic runtime with message passing
- ▸Automatic Reference Counting (ARC) for memory management
- ▸Protocol-based polymorphism
- ▸Interoperable with C and C++ code
Origin & Creator
Developed in the early 1980s by Brad Cox and Tom Love, combining C with Smalltalk-style object-oriented messaging.
Industrial Note
Objective-C remains critical for maintaining legacy macOS and iOS applications and for interfacing with older Apple frameworks that are not fully migrated to Swift.