// Create a feed id
let feedId = FeedId(group: "user", id: "john")
// Create the feed instance from your client
let feed = client.feed(for: feedId)
// Get the latest data
try await feed.getOrCreate()
// Access the state
let feedState = feed.stateState Layer
The State layer provides observable state management for feeds and activities in Stream Feeds. It uses @Published properties to automatically update your UI when data changes.
FeedState
FeedState manages the state of a feed, including activities, followers, members, and pagination information. It’s an ObservableObject that automatically updates when the feed data changes.
Getting FeedState
To access the state of a feed, you need to create a Feed instance and access its state property:
Available Properties
The FeedState provides the following published properties:
// Core feed data
@Published var feed: FeedData?                          // The feed information
@Published var activities: [ActivityData] = []         // Activities in the feed
@Published var ownCapabilities: [FeedOwnCapability] = [] // Your permissions
// Follow relationships
@Published var followers: [FollowData] = []            // Users following this feed
@Published var following: [FollowData] = []            // Feeds this user follows
@Published var followRequests: [FollowData] = []       // Pending follow requests
// Feed members
@Published var members: [FeedMemberData] = []          // Members of the feed
// Pagination
@Published var canLoadMoreActivities: Bool = false     // Whether more activities can be loadedActivityState
ActivityState manages the state of a single activity, including its comments, reactions, and associated poll data. It’s also an ObservableObject that updates automatically.
Getting ActivityState
To access the state of an activity, you need to create an Activity instance:
// Create an activity instance
let activity = client.activity(
    activityId: "activity-123",
    feedId: FeedId(group: "user", id: "john")
)
// Get the latest data
try await activity.get()
// Access the state
let activityState = activity.stateAvailable Properties
The ActivityState provides the following properties:
@Published var activity: ActivityData?             // The activity data
@Published var comments: [ThreadedCommentData] = [] // Comments on the activity
@Published var poll: PollData?                     // Associated poll (if any)