Skip to content

Fix: Add public initializers for SavedFeed and SavedFeedPreferencesVe…#200

Merged
MasterJ93 merged 1 commit intoMasterJ93:mainfrom
P24L:fix/savefeed-init
Jul 23, 2025
Merged

Fix: Add public initializers for SavedFeed and SavedFeedPreferencesVe…#200
MasterJ93 merged 1 commit intoMasterJ93:mainfrom
P24L:fix/savefeed-init

Conversation

@P24L
Copy link
Contributor

@P24L P24L commented Jul 21, 2025

Problem

When working with saved feeds preferences, it's currently impossible to create instances of SavedFeed and SavedFeedPreferencesVersion2Definition without using JSON serialization workarounds. These structs only have Decodable initializers, which makes programmatic creation unnecessarily complex.

Solution

This PR adds public initializers for:

  • AppBskyLexicon.Actor.SavedFeed
  • AppBskyLexicon.Actor.SavedFeedPreferencesVersion2Definition

Changes

Added public initializers following ATProtoKit's strict guidelines:

  • Proper documentation with triple slashes
  • All parameters documented
  • Follows the established code structure pattern

Testing

The initializers have been tested to ensure they create objects identical to those decoded from JSON responses.

Example Usage

// Before (workaround required)
let savedFeedDict: [String: Any] = [
    "id": UUID().uuidString,
    "type": "list",
    "pinned": true,
    "$type": "app.bsky.actor.defs#savedFeed",
    "value": listURI
]
let jsonData = try JSONSerialization.data(withJSONObject: savedFeedDict)
let savedFeed = try JSONDecoder().decode(SavedFeed.self, from: jsonData)

// After (with this PR)
let savedFeed = SavedFeed(
    feedID: UUID().uuidString,
    feedType: .list,
    value: listURI,
    isPinned: true
)

@MasterJ93
Copy link
Owner

Thanks for the PR. I'll go ahead and merge it now.

@MasterJ93 MasterJ93 merged commit 3b1d139 into MasterJ93:main Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants