- Launguage : 🇰🇷
k-sdui-ios is a library that helps you easily implement Server-Driven UI in SwiftUI.
Renders SwiftUI views by decoding JSON into view components based on their types.
- CommonComponent : Defines shared SwiftUI view modifiers
- TextComponent : Renders as SwiftUI
Text - ButtonComponent : Renders as SwiftUI
Button - ImageComponent : Renders as SwiftUI
ImageorAsyncImage - SpacerComponent : Renders as SwiftUI
Spacer - RectangleComponent : Renders as SwiftUI
Rectangle - RoundedRectangleComponent : Renders as SwiftUI
RoundedRectangle - ScrollComponent : Renders as SwiftUI
ScrollView - CustomComponent : Renders as SwiftUI
EmptyView - Layout : Renders as SwiftUI
HStack,VStack,ZStack,LazyHStack,LazyVStack
This code demonstrates how to load and inspect the structure of each JSON file located in the Example directory.
- Decode
SDUIScene - Define layout using
SDUIScene→SDUIContainer→SDUILayoutand include an array ofSDUIViews - Use the
renderfunction to convert into SwiftUI Views
public struct SDUIScene: Codable, Identifiable {
public let id = UUID()
public var hasNavigationBar: Bool
public var container: SDUIContainer
...
hasNavigationBar: Indicates whether to show a navigation barcontainer: Top-level container view
public struct SDUILayout: Codable {
public var type: String
public var spacing: CGFloat?
public var alignment: String
...
type: RendersHStack,VStack, orZStackbased onh,v, orz. Forlhorlv, it rendersLazyHStackorLazyVStackspacing: Spacing between viewsalignment: Alignment direction
All components conform to this protocol.
public protocol CommonComponent: Codable {
var componentId: String { get }
var padding: [PaddingComponent]? { get }
var frame: FrameComponent? { get }
var extreamFrame: ExtreamFrameComponent? { get }
var foregroundColor: String? { get }
var backgroundColor: String? { get }
var cornerRadius: CGFloat? { get }
var overlay: SDUIView? { get }
}componentId: Unique identifier for the componentpadding: Applies padding with specified edges and spacingframe: Applies width/height-style frame modifiersextreamFrame: Applies minWidth/minHeight-style frame modifiersforegroundColor: AppliesforegroundStylemodifierbackgroundColor: AppliesbackgroundmodifiercornerRadius: Applies corner radiusoverlay: Applies overlay modifier
public struct TextComponent: CommonComponent {
... CommonComponent
public let text: String
public let font: FontComponent?
public let lineLimit: Int?
...
text: The string to displayfont: Applies font modifierslineLimit: Maximum number of lines
public struct ButtonComponent: CommonComponent {
... CommonComponent
public let text: String
public let action: ActionComponent?
public let customViews: SDUIView?
...
text: Used when rendering a simple text-based buttonaction: Action handler if definedcustomViews: Used for custom button content
public struct ImageComponent: CommonComponent {
... CommonComponent
public let imageURL: String
...
imageURL: If it’s a valid URL, renders withAsyncImage. Otherwise, uses asset name to renderImage
public struct SpacerComponent: CommonComponent {
... CommonComponent
public struct RectangleComponent: CommonComponent {
... CommonComponent
public struct RoundedRectangleComponent: CommonComponent {
... CommonComponent
public let strokeComponent: StrokeComponent?
...
strokeComponent: Applies stroke color and line width
public struct ScrollComponent: CommonComponent {
... CommonComponent
public let axis: String
public let showIndicator: Bool
public let containerViews: SDUIView
...
axis: Scroll direction (horizontal or vertical)showIndicator: Whether to show scroll indicatorscontainerViews: Views contained within the scroll view
public struct CustomComponent: CommonComponent {
... CommonComponent
public struct SDUIContainer: CommonComponent {
... CommonComponent
public var layout: SDUILayout
public var views: [SDUIView]
...
layout: Defines layout structureviews: Array of views inside the layout

