# SDK for iOS methods
The SDK for iOS is equipped to handle all essential event calls, including `screen`, `track`, `identify`, and `group`. Furthermore, it offers functionalities to efficiently manage session information.
With these capabilities, you can seamlessly track and analyze user interactions, facilitating a comprehensive understanding of user behavior and engagement.
Below the SDK for iOS methods:
- [screen](#screen)
- [track](#track)
- [identify](#identify)
- [group](#group)
- [userId](#userid)
- [traits](#traits)
- [alias](#alias)
- [anonymousId](#anonymousid)
- [reset](#reset)
- [getSessionId](#getsessionid)
- [startSession](#startsession)
- [endSession](#endsession)
## screen
The screen method implements the [screen call](https://www.krenalis.com/docs/collect-events/spec/screen.md).
The screen call enables you to capture instances when a user views a screen and record associated properties or details about that particular screen.
#### Syntax
```swift
screen(title: String, category: String? = nil, properties: P?)
```
#### Parameters
| Name | Type | Required | Description |
|--------------|----------------|----------------------------------------|----------------------------------|
| `title` | `String` |
✓
| Title of the screen. |
| `category` | `String?` | | Category to describe the screen. |
| `properties` | `P: Encodable` | | Properties of the screen. |
#### Example
```swift
analytics.screen(title: "Order completed", properties: [
"items": 3,
"total": 274.99
])
```
## track
The track method implements the [track call](https://www.krenalis.com/docs/collect-events/spec/track.md).
The track call is used to send specific events or pipelines, and associated properties, that occur when users interact with your application or website.
#### Syntax
```swift
track(name: String, properties: P?)
```
#### Parameters
| Name | Type | Required | Description |
|--------------|----------------|----------------------------------------|--------------------------|
| `name` | `String` | ✓
| Name of the event. |
| `properties` | `P: Encodable` | | Properties of the event. |
#### Example
```swift
analytics.track(name: "Product added to cart", properties: [
"id": 12345
])
```
## identify
The identify method implements the [identify call](https://www.krenalis.com/docs/collect-events/spec/identify.md).
Through an identify call, you can connect previous and upcoming events to a recognized user and save details about them along with their events, such as name and email. The user information can also be utilized to update and enhance unified data from other sources.
#### Syntax
```swift
identify(userId: String, traits: T?)
```
#### Parameters
| Name | Type | Required | Description |
|----------|----------------|----------------------------------------|-------------------------------------|
| `userId` | `String` | ✓
| Identifier of the user. |
| `traits` | `T: Encodable` | | Traits to add to the user's traits. |
#### Example
```swift
analytics.identify(userId: "59a20n37ec82", traits: [
"firstName": "Emily",
"lastName": "Johnson",
"email": "emma.johnson@example.com"
])
```
## group
The `group` method implements the [group call](https://www.krenalis.com/docs/collect-events/spec/group.md).
The group call provides a way to associate individual users with groups, such as a company, organization, team, association, or initiative. A user who has been identified can be associated with several groups.
#### Syntax
```swift
group(groupId: String, traits: T?)
```
#### Parameters
| Name | Type | Required | Description |
|-----------|----------------|----------------------------------------|--------------------------|
| `groupId` | `String` | ✓
| Identifier of the group. |
| `traits` | `T: Encodable` | | Traits of the group. |
#### Example
```swift
analytics.group(groupId: "84s76y49tb28v1jxq", traits: [
"name": "AcmeTech",
"industry": "Technology",
"employeeCount": 100
])
```
## traits
The `traits` method is used to retrieve a user's traits. These traits are for the anonymous user if the user is anonymous, and for the non-anonymous user if non-anonymous.
To modify the user's traits, use the [`identify`](#identify) method or the [`reset`](#reset) method.
#### Syntax
```swift
traits() -> [String: Any]?
```
#### Parameters
There are no parameters.
#### Example
```swift
let traits = analytics.traits()
```
## alias
The `alias` method is used to merge two user identities, effectively connecting two sets of user data as one. This method is applicable when the event is sent to a destination, such as Mixpanel.
> In Krenalis, user merging is handled by Krenalis's Identity Resolution. Therefore this method is not utilized in this process.
#### Syntax
```swift
alias(newId: String)
```
#### Parameters
| Name | Type | Required | Description |
|---------|----------|----------------------------------------|--------------------------------------------------|
| `newId` | `String` | ✓
| The new ID you want to alias the existing ID to. |
#### Example
```swift
analytics.alias(newId: "12r60m18ff04")
```
## reset
The `reset` method resets the user identifier, and updates or removes the Anonymous ID and traits according to the strategy (as detailed in the table below). If `all` is true it always resets the Anonymous ID by generating a new one, and ends the session if one exists, regardless of the strategy.
| Strategy | Behavior of `reset()` |
|--------------|--------------------------------------------------------------------------------------------------------------------------------|
| Conversion | Removes User ID and user traits, and changes Anonymous ID and session. |
| Fusion | Removes User ID and user traits. Does not change Anonymous ID or session. |
| Isolation | Removes User ID and user traits and changes Anonymous ID and session. |
| Preservation | Removes User ID. Restores Anonymous ID, user traits and session to their state before the latest [`identify`](#identify) call. |
#### Syntax
```swift
reset(all: Bool = false)
```
#### Parameters
| Name | Type | Required | Description |
|-------|--------|----------|------------------------------------------------------------------------------------------|
| `all` | `Bool` | | Indicates if the Anonymous ID and the session must be reset, regardless of the strategy. |
#### Example
```swift
analytics.reset()
```
#### Segment Compatibility
To align with Segment's `reset()` behavior, choose the "Conversion" or "Isolation" strategy in Krenalis. Note that `reset(all: true)` is not available in Segment.
#### RudderStack Compatibility
To match RudderStack's `reset()` behavior, choose the "Conversion" or "Isolation" strategy in Krenalis. In Krenalis, `reset(all: true)` works the same way as it does in RudderStack for all strategies.
## getSessionId
The `getSessionId` method returns the current session identifier. It returns `nil` if there is no session.
#### Syntax
```swift
getSessionId() -> Int64?
```
#### Parameters
There are no parameters.
#### Example
```swift
let sessionId = analytics.getSessionId()
```
## startSession
The `startSession` method starts a new session using the provided identifier. If the identifier provided is `nil`, it generates one automatically using the current time in milliseconds. The provided session ID, if not `nil`, must be a positive `Int64`.
#### Syntax
```swift
startSession(id: Int64? = nil)
```
#### Parameters
| Name | Type | Required | Description |
|------|----------|----------|---------------------------------------|
| `id` | `Int64?` | | Session identifier. Must be positive. |
#### Example
```swift
analytics.startSession(id: 123456789)
```
## endSession
The `endSession` method ends the session.
#### Syntax
```swift
endSession()
```
#### Parameters
There are no parameters.
#### Example
```swift
analytics.endSession()
```