New Features in iOS (Swift) SDK
Learn about the new and improved features in iOS (Swift) SDK compared to the iOS (Obj-C) SDK.
This section highlights the new and improved features in the iOS (Swift) SDK compared to the iOS (Obj-C) SDK.
New features
The iOS (Swift) SDK introduces several features not available in the iOS (Obj-C) SDK.
Modern Swift concurrency
The iOS (Swift) SDK is built with async-await and structured concurrency. It uses reactive state management for better performance and reliability, and non-blocking operations for improved app responsiveness.
The SDK adds native support for macOS 12.0+ and provides a unified API across all Apple platforms. It leverages the latest iOS 15.0+, macOS 12.0+, tvOS 15.0+, and watchOS 8.0+ features.
Custom plugins
Custom plugins let you intercept and transform events at any point in the analytics pipeline. With this feature, you can:
- Enrich events with device context
- Filter out sensitive data or drop specific information (for example,
Application Opened and Application Backgrounded events) before it leaves the device.
The new plugin system lets you add, remove, or modify custom plugins at runtime.
// Create custom plugins
import RudderStackAnalytics
final class CustomEventFilter: Plugin {
var pluginType: PluginType = .onProcess
var analytics: Analytics?
func setup(analytics: Analytics) {
self.analytics = analytics
}
func intercept(event: any Event) -> (any Event)? {
// Custom filtering logic
return event
}
}
analytics.add(plugin: CustomEventFilter())
See the Custom plugins guide for more information.
Multiple analytics instances
You can create and manage multiple analytics instances with different configurations.
Each instance maintains its own independent state, storage, and configuration — this is particularly useful for multi-tenant applications or tracking different data streams.
See the Multiple Instance Support guide for more information.
Custom logger
Use a centralized custom logger abstraction with pluggable implementations and global log-level configuration.
See the Logging APIs in Mobile SDKs guide for more information.
Custom plugins in integrations
You can add custom plugins to any supported integration to enhance event handling and processing.
Click here for an example that shows how to create a custom plugin for a destination. You can use it as a template for your own custom plugins.
The following example highlights a sample plugin that transforms (normalizes) track event names before they are sent to the Braze destination.
1. Create a custom plugin
import Foundation
import RudderStackAnalytics
class EventNameNormalizationPlugin: Plugin {
var pluginType: PluginType = .onProcess
var analytics: Analytics?
/** Called when the plugin is added to the analytics instance */
func setup(analytics: Analytics) {
self.analytics = analytics
}
/**
Intercepts analytics events and normalizes track event names by replacing spaces with underscores.
- Parameter event: The event to modify
- Returns: The modified event with normalized event name
*/
func intercept(event: any Event) -> (any Event)? {
// Only process track events
guard var trackEvent = event as? TrackEvent else {
return event
}
let originalEventName = trackEvent.event
let normalizedEventName = originalEventName
.trimmingCharacters(in: .whitespaces)
.replacingOccurrences(of: " ", with: "_")
trackEvent.event = normalizedEventName
LoggerAnalytics.verbose("EventNameNormalizationPlugin: Transformed event name from \"\(originalEventName)\" to \"\(normalizedEventName)\"")
return trackEvent
}
}
2. Usage
1: Create and add the Braze integration to the SDK:
let brazeIntegration = BrazeIntegration()
analytics.add(plugin: brazeIntegration)
2: Add the custom plugin to the Braze integration:
brazeIntegration.add(plugin: EventNameNormalizationPlugin())
- Track events.
analytics.track("Product Added")
// The event will be transformed to: "Product_Added"
analytics.track("Checkout Started")
// The event will be transformed to: "Checkout_Started"
Behavior
Note that the above custom plugin:
- Only modifies
track events. It does not modify other event types (identify, screen, etc.). - Replaces all spaces with underscores in event names.
- Logs transformations for debugging purposes.
Shutdown API
You can explicitly shut down the analytics instance to terminate all ongoing operations. The SDK automatically removes all registered plugins and releases allocated resources. All events recorded before shutdown are persisted and processed on the next startup.
See the Shutdown API guide for more information.
Questions? Contact us by Email or on
Slack