objective-c
/objective-c
Pomaga w Objective-C: przekazywanie komunikatów, dynamiczne rozwiązywanie metod w runtime, ARC, Foundation i Cocoa, przy starszych bazach Apple, natywnych frameworkach iOS i macOS oraz interop z C++.
- Autor
- G1Joshi ↗
- Repozytorium
- Agent-Skills ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 01.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 1
Brak sygnałów. Repozytorium zmienione 01.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Pomaga w Objective-C: przekazywanie komunikatów, dynamiczne rozwiązywanie metod w runtime, ARC, Foundation i Cocoa, przy starszych bazach Apple, natywnych frameworkach iOS i macOS oraz interop z C++.
Oryginalny opis (EN)
Expert Objective-C assistance covering message passing, runtime dynamic method resolution, ARC, and Foundation/Cocoa. Use when maintaining Apple legacy codebases, developing native iOS/macOS frameworks, or C++ interop.
Jak działa
- When to Use
- Quick Start
- Core Concepts
- Common Patterns
- Best Practices
- Troubleshooting
- References
Podgląd SKILL.md
---
name: objective-c
description: Expert Objective-C assistance covering message passing, runtime dynamic method resolution, ARC, and Foundation/Cocoa. Use when maintaining Apple legacy codebases, developing native iOS/macOS frameworks, or C++ interop.
---
# Objective-C
Objective-C is in **maintenance mode**. New features are rare, but it powers the Apple ecosystem's foundation. It allows mixing C++ (`.mm`) loosely.
## When to Use
- **Legacy iOS and macOS Codebase Maintenance**: Maintaining established Apple applications built before Swift.
- **C/C++ and Swift Bridging (Objective-C++)**: Acting as a high-performance interoperability bridge between native C++ engines and modern Swift.
- **Dynamic Runtime Introspection**: Leveraging the dynamic Objective-C runtime for method swizzling and dynamic message forwarding.
- **High-Performance Audio & Core Audio Frameworks**: Interfacing with low-level Apple media frameworks where C pointer interop is required.
## Quick Start
```objc
#import <Foundation/Foundation.h>
@interface Person : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, assign) NSInteger age;
- (void)sayHello;
@end
@implementation Person
- (void)sayHello {
NSLog(@"Hello, my name is %@", self.name);
}
@end
```
## Core Concepts
### Dynamic Message Passing (`[receiver message]`)
Method calls in Objective-C are dynamic messages resolved at runtime via `objc_msgSend`:
```objc
#import <Foundation/Foundation.h>
@interface OrderService : NSObject
- (BOOL)processPayment:(double)amount forCustomer:(NSString *)customer;
@end
@implementation OrderService
- (BOOL)processPayment:(double)amount forCustomer:(NSString *)customer {
NSLog(@"Charging %@: $%.2f", customer, amount);
return amount > 0.0;
}
@end
// Invocation syntax
OrderService *service = [[OrderService alloc] init];
[service processPayment:150.0 forCustomer:@"Alice"];
```
### Automatic Reference Counting (ARC) & Nullability Annotations
Manages object memory automatically at compile time with strong/weak ownership semantics:
```objc
@property (nonatomic, strong) NSString *accountNumber;
@property (nonatomic, weak) id<OrderDelegate> delegate; // Prevents retain cycles
@property (nonatomic, copy) void (^completionHandler)(BOOL success);
```
### Objective-C++ (`.mm`) Bridging
Seamlessly mixes C++ standard library types with Cocoa objects in the same file:
```objc
// ProcessorBridge.mm (Objective-C++)
#include <vector>
#import "ProcessorBridge.h"
@implementation ProcessorBridge {
std::vector<double> _signalBuffer;
}
- (void)addSample:(double)sample {
_signalBuffer.push_back(sample);
}
@end
```
## Common Patterns
### Safe Block Self-Capture to Prevent Retain Cycles
**Problem**: Strong reference cycles in asynchronous blocks cause permanent memory leaks under ARC.
**Solution**:
Use the `weakSelf / strongSelf` dance in completion blocks:
```objc
__weak typeof(self) weakSelf = self;
[self.networkClient fetchProfileWithCompletion:^(NSDictionary *data) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) return;
[strongSelf updateUIWithData:data];
}];
```
## Best Practices
**Do**:
- Add Nullability Annotations (`_Nonnull`, `_Nullable`): Ensure smooth, idiomatic bridging into modern Swift codebases.
- Use Weak References for Delegates: Mark all delegate properties as `weak` to eliminate memory retain cycles.
- Use Objective-C Generics: Parameterize collections (`NSArray<NSString *> *`) for compile-time type safety.
- Wrap Bridged Code with Modern Swift Interfaces: Plan incremental migrations by creating Swift wrapper classes.
**Don't**:
- Start new greenfield Apple applications in Objective-C: Build all new iOS/macOS applications in Swift and SwiftUI.
- Invoke methods on deallocated objects without weak-strong dancing: Use `__weak typeof(self) weakSelf = self;` in asynchronous blocks.
- Use manual retain/release (MRR): Ensure modern ARC (`-fobjc-arc`) is enabled across all targets.
## Troubleshooting
| Error | Cause | Solution |
| :--------------------------------------------- | :--------------------------------------------------------- | :--------------------------------------------------------------------------------------------------- |
| `unrecognized selector sent to instance ...` | Invoking a method not implemented by the receiving object. | Verify method name and colons (e.g. `doAction:` vs `doAction`), or check with `respondsToSelector:`. |
| `EXC_BAD_ACCESS (code=1, address=...)` | Dereferencing deallocated memory or zombie object. | Enable Zombie Objects in Xcode scheme diagnostics to locate deallocated reference. |
| `Property with 'copy' attribute is not copied` | Custom setter failed to call `[newValue copy]`. | Implement custom setters using `_prop = [newValue copy];`. |
## References
- [Apple Developer Documentation](https://developer.apple.com/)
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · G1Joshi/Agent-Skills | 100 | MIT |
| dkbnull/hello-skill | 90 | MIT |
Migawka bazy z 13.11.2026 · wersja paczki 3ab1552aa921 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100xmake-objc
Buduje projekty Objective-C i Objective-C++ w xmake: pliki .m i .mm, frameworki Cocoa, mieszanie z C++ i cele Apple. - 95sentry-cocoa-sdk
Konfiguruje Sentry w aplikacjach Apple: monitorowanie błędów, tracing, profilowanie, replay i logi dla iOS i macOS. - 100xmake-swift
Buduje projekty Swift w xmake: pliki binarne i biblioteki, interop z C++ i Objective-C oraz konfigurację modułów dla iOS i macOS. - 90desktop-appkit
Pomaga w tworzeniu aplikacji macOS w AppKit i Cocoa, w tym w Swift AppKit i architekturze natywnych aplikacji Mac. - 90native
Podpowiada strategie tworzenia natywnych aplikacji na Apple (iOS, macOS) i pulpit w Tauri. - 100sentry-cocoa-sdk
Konfiguruje SDK Sentry dla platform Apple (iOS, macOS, tvOS, watchOS, visionOS): monitoring błędów, tracing, profilowanie, session replay i logi, dla SwiftUI i UIKit.