Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ fileignoreconfig:
fileignoreconfig:
- filename: ContentstackSwift.xcodeproj/project.pbxproj
checksum: b743f609350e19c2a05a2081f3af3f723992b9610b3b3e6aa402792cad1de2c5
fileignoreconfig:
- filename: ContentstackSwift.xcodeproj/xcshareddata/xcschemes/ContentstackSwift iOS Tests.xcscheme
checksum: e42ad1f8d37ce872bbcaf7060424f7f927a8603a7ca6946b7c6be55321ecc3b3
- filename: ContentstackSwift.xcodeproj/project.pbxproj
checksum: d4519d6ed11d86cac351a4057d3504e33ee8eee22fab000dec160db67f4ea50d
version: "1.0"


Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## v2.5.0

### Date: 27-Jul-2026

### Feature

- Branch support in entry variants

## v2.4.0

Expand Down
8 changes: 8 additions & 0 deletions ContentstackSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@
67AA39162EBA065000C0E2C0 /* StackInitializationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67AA39152EBA065000C0E2C0 /* StackInitializationTest.swift */; };
67AA39172EBA065000C0E2C0 /* StackInitializationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67AA39152EBA065000C0E2C0 /* StackInitializationTest.swift */; };
67AA39182EBA065000C0E2C0 /* StackInitializationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67AA39152EBA065000C0E2C0 /* StackInitializationTest.swift */; };
67B30E7B2FB6F98D00C9FA26 /* EntryVariantsAPITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B30E7A2FB6F98D00C9FA26 /* EntryVariantsAPITest.swift */; };
67B30E7C2FB6F98D00C9FA26 /* EntryVariantsAPITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B30E7A2FB6F98D00C9FA26 /* EntryVariantsAPITest.swift */; };
67B30E7D2FB6F98D00C9FA26 /* EntryVariantsAPITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67B30E7A2FB6F98D00C9FA26 /* EntryVariantsAPITest.swift */; };
67BA83032F6D36F3005006B8 /* config.json in Resources */ = {isa = PBXBuildFile; fileRef = 67BA83022F6D36ED005006B8 /* config.json */; };
67BA83042F6D36F3005006B8 /* config.json in Resources */ = {isa = PBXBuildFile; fileRef = 67BA83022F6D36ED005006B8 /* config.json */; };
67BA83052F6D36F3005006B8 /* config.json in Resources */ = {isa = PBXBuildFile; fileRef = 67BA83022F6D36ED005006B8 /* config.json */; };
Expand Down Expand Up @@ -488,6 +491,7 @@
67AA390D2EB9D49600C0E2C0 /* CSDefinitionsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSDefinitionsTest.swift; sourceTree = "<group>"; };
67AA39112EBA063300C0E2C0 /* TaxonomyUnitTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaxonomyUnitTest.swift; sourceTree = "<group>"; };
67AA39152EBA065000C0E2C0 /* StackInitializationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StackInitializationTest.swift; sourceTree = "<group>"; };
67B30E7A2FB6F98D00C9FA26 /* EntryVariantsAPITest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EntryVariantsAPITest.swift; sourceTree = "<group>"; };
67BA83022F6D36ED005006B8 /* config.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = config.json; sourceTree = "<group>"; };
67BF4D822FE53F4D00DD4DFC /* ContentstackEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentstackEndpoint.swift; sourceTree = "<group>"; };
67EE21DE2DDB3FFE005AC119 /* CSURLSessionDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSURLSessionDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -760,6 +764,7 @@
0F50EA1C244ED88C00E5D705 /* StackCacheAPITest.swift */,
470657532B5E785C00BBFF88 /* ContentTypeQueryAPITest.swift */,
470657572B5E788400BBFF88 /* EntryAPITest.swift */,
67B30E7A2FB6F98D00C9FA26 /* EntryVariantsAPITest.swift */,
4706575B2B5E78B300BBFF88 /* AssetQueryAPITest.swift */,
4706575F2B5E797300BBFF88 /* ContentstackTest.swift */,
47AAE08F2B60420E0098655A /* SyncAPITest.swift */,
Expand Down Expand Up @@ -1235,6 +1240,7 @@
0F60CA2F2428949C00ED67E6 /* EntryTest.swift in Sources */,
0F244FA724406A4A003C3F26 /* EntryQueriableTest.swift in Sources */,
67AA38EB2EB9D44800C0E2C0 /* CSDefinitionsTest.swift in Sources */,
67B30E7C2FB6F98D00C9FA26 /* EntryVariantsAPITest.swift in Sources */,
0F463113243B044F001CE1FA /* SyncTest.swift in Sources */,
67AA39142EBA063300C0E2C0 /* TaxonomyUnitTest.swift in Sources */,
67AA38F72EB9D46D00C0E2C0 /* QueryableRangeTest.swift in Sources */,
Expand Down Expand Up @@ -1333,6 +1339,7 @@
0F60CA302428949C00ED67E6 /* EntryTest.swift in Sources */,
0F244FA824406A4A003C3F26 /* EntryQueriableTest.swift in Sources */,
67AA38EC2EB9D44800C0E2C0 /* CSDefinitionsTest.swift in Sources */,
67B30E7D2FB6F98D00C9FA26 /* EntryVariantsAPITest.swift in Sources */,
0F463114243B044F001CE1FA /* SyncTest.swift in Sources */,
67AA39132EBA063300C0E2C0 /* TaxonomyUnitTest.swift in Sources */,
67AA38F62EB9D46D00C0E2C0 /* QueryableRangeTest.swift in Sources */,
Expand Down Expand Up @@ -1431,6 +1438,7 @@
0F60CA312428949C00ED67E6 /* EntryTest.swift in Sources */,
0F244FA924406A4A003C3F26 /* EntryQueriableTest.swift in Sources */,
67AA38EA2EB9D44800C0E2C0 /* CSDefinitionsTest.swift in Sources */,
67B30E7B2FB6F98D00C9FA26 /* EntryVariantsAPITest.swift in Sources */,
0F463115243B044F001CE1FA /* SyncTest.swift in Sources */,
67AA39122EBA063300C0E2C0 /* TaxonomyUnitTest.swift in Sources */,
67AA38F82EB9D46D00C0E2C0 /* QueryableRangeTest.swift in Sources */,
Expand Down
10 changes: 0 additions & 10 deletions Sources/Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ public class Entry: EntryQueryable, CachePolicyAccessible {
return query
}

public func variants(uid: String) -> Self {
self.headers["x-cs-variant-uid"] = uid
return self
}

public func variants(uids: [String]) -> Self {
self.headers["x-cs-variant-uid"] = uids.joined(separator: ",")
return self
}

/// The Query parameters dictionary that are converted to `URLComponents`.
/// - Parameters:
/// - key: The key for header parameter,
Expand Down
91 changes: 88 additions & 3 deletions Sources/EntryQuaryable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,92 @@ extension EntryQueryable {
}
return query
}




/// Sets the variant UID header so the request fetches a specific entry variant.
/// - Parameter uid: A single variant UID.
/// - Returns: A reference to the receiving object to enable chaining.
///
/// Example usage:
/// ```
/// stack.contentType(uid: contentTypeUID).entry(uid: entryUID)
/// .variants(uid: "variant_uid")
/// .fetch { ... }
///
/// stack.contentType(uid: contentTypeUID).entry().query()
/// .variants(uid: "variant_uid")
/// .find { ... }
/// ```
@discardableResult
public func variants(uid: String) -> Self {
self.headers["x-cs-variant-uid"] = uid
return self
}

/// Sets the variant UID header for multiple variant UIDs.
/// - Parameter uids: An array of variant UIDs.
/// - Returns: A reference to the receiving object to enable chaining.
///
/// Example usage:
/// ```
/// stack.contentType(uid: contentTypeUID).entry(uid: entryUID)
/// .variants(uids: ["v1", "v2"])
/// .fetch { ... }
///
/// stack.contentType(uid: contentTypeUID).entry().query()
/// .variants(uids: ["v1", "v2"])
/// .find { ... }
/// ```
@discardableResult
public func variants(uids: [String]) -> Self {
self.headers["x-cs-variant-uid"] = uids.joined(separator: ",")
return self
}

/// Sets the variant UID and branch headers so the request fetches a specific entry variant
/// scoped to the given branch.
/// - Parameters:
/// - uid: A single variant UID.
/// - branch: The branch name to scope the request to.
/// - Returns: A reference to the receiving object to enable chaining.
///
/// Example usage:
/// ```
/// stack.contentType(uid: contentTypeUID).entry(uid: entryUID)
/// .variants(uid: "variant_uid", branch: "staging")
/// .fetch { ... }
///
/// stack.contentType(uid: contentTypeUID).entry().query()
/// .variants(uid: "variant_uid", branch: "staging")
/// .find { ... }
/// ```
@discardableResult
public func variants(uid: String, branch: String) -> Self {
self.headers["x-cs-variant-uid"] = uid
self.headers["branch"] = branch
return self
}

/// Sets the variant UIDs and branch headers so the request fetches specific entry variants
/// scoped to the given branch.
/// - Parameters:
/// - uids: An array of variant UIDs.
/// - branch: The branch name to scope the request to.
/// - Returns: A reference to the receiving object to enable chaining.
///
/// Example usage:
/// ```
/// stack.contentType(uid: contentTypeUID).entry(uid: entryUID)
/// .variants(uids: ["v1", "v2"], branch: "staging")
/// .fetch { ... }
///
/// stack.contentType(uid: contentTypeUID).entry().query()
/// .variants(uids: ["v1", "v2"], branch: "staging")
/// .find { ... }
/// ```
@discardableResult
public func variants(uids: [String], branch: String) -> Self {
self.headers["x-cs-variant-uid"] = uids.joined(separator: ",")
self.headers["branch"] = branch
return self
}
}
71 changes: 71 additions & 0 deletions Tests/DVRRecordings/EntryVariants.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"name" : "EntryVariants",
"interactions" : [
{
"request" : {
"url" : "https:\/\/cdn.contentstack.io\/v3\/content_types\/blog\/entries?environment=environment",
"headers" : {
"access_token" : "delivery_token",
"api_key" : "api_key",
"X-User-Agent" : "contentstack-swift\/1.0.0",
"x-cs-variant-uid" : "cs7587bd1cb52b5479"
},
"method" : "GET"
},
"recorded_at" : 1715769600.0,
"response" : {
"url" : "https:\/\/cdn.contentstack.io\/v3\/content_types\/blog\/entries?environment=environment",
"status" : 200,
"headers" : {
"Content-Type" : "application\/json",
"Access-Control-Allow-Origin" : "*"
},
"body" : {
"entries" : [
{
"uid" : "blog_entry_uid_1",
"title" : "Variant Test Blog Post",
"locale" : "en-us",
"created_at" : "2024-01-10T05:47:46.833Z",
"updated_at" : "2024-04-20T07:05:15.592Z",
"created_by" : "user_uid_1",
"updated_by" : "user_uid_1"
}
]
}
}
},
{
"request" : {
"url" : "https:\/\/cdn.contentstack.io\/v3\/content_types\/blog\/entries\/blog_entry_uid_1?environment=environment",
"headers" : {
"access_token" : "delivery_token",
"api_key" : "api_key",
"X-User-Agent" : "contentstack-swift\/1.0.0",
"x-cs-variant-uid" : "cs7587bd1cb52b5479"
},
"method" : "GET"
},
"recorded_at" : 1715769600.0,
"response" : {
"url" : "https:\/\/cdn.contentstack.io\/v3\/content_types\/blog\/entries\/blog_entry_uid_1?environment=environment",
"status" : 200,
"headers" : {
"Content-Type" : "application\/json",
"Access-Control-Allow-Origin" : "*"
},
"body" : {
"entry" : {
"uid" : "blog_entry_uid_1",
"title" : "Variant Test Blog Post",
"locale" : "en-us",
"created_at" : "2024-01-10T05:47:46.833Z",
"updated_at" : "2024-04-20T07:05:15.592Z",
"created_by" : "user_uid_1",
"updated_by" : "user_uid_1"
}
}
}
}
]
}
14 changes: 14 additions & 0 deletions Tests/EntryTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,19 @@ class EntryTest: XCTestCase {
XCTAssertEqual(entry.headers.keys.count, 1)
XCTAssertEqual(entry.headers["x-cs-variant-uid"], "variant1,variant2,variant3")
}

func testSingleVariantWithBranch() {
let entry = makeEntrySut(contentTypeuid: "Content_type", entryUid: "entry_uid").variants(uid: "variant1", branch: "staging")
XCTAssertEqual(entry.headers.keys.count, 2)
XCTAssertEqual(entry.headers["x-cs-variant-uid"], "variant1")
XCTAssertEqual(entry.headers["branch"], "staging")
}

func testMultipleVariantsWithBranch() {
let entry = makeEntrySut(contentTypeuid: "Content_type", entryUid: "entry_uid").variants(uids: ["variant1", "variant2"], branch: "staging")
XCTAssertEqual(entry.headers.keys.count, 2)
XCTAssertEqual(entry.headers["x-cs-variant-uid"], "variant1,variant2")
XCTAssertEqual(entry.headers["branch"], "staging")
}
}

Loading