Skip to content

Commit b4d4f75

Browse files
committed
Add code documentation comments for all public APIs
1 parent 4c66afe commit b4d4f75

File tree

7 files changed

+353
-3
lines changed

7 files changed

+353
-3
lines changed

Images/Logo.png

22.9 KB
Loading

Sources/LinksKit/LinksKit.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import Foundation
22

3+
/// The wrapper to configure LinksKit.
34
public actor LinksKit {
45
static var providerToken: String = ""
56
static var linkSections: [LinkSection] = []
67

8+
/// The main configuration method to be called upon app start to confure the contents of ``LinksView`` for use in settings/help menu.
9+
///
10+
/// - Parameters:
11+
/// - providerToken: The `pt` query parameter of your app's campaign link. Same for all your apps, thus provided here on top level.
12+
/// - linkSections: The separate link sections you want to auto-render. Use one of the convenience helpers `.helpLinks`, `.socialMenus`, `.appMenus`, `.legalLinks`, or pass a custom ``LegalSection`` with the links/menus of your choice.
713
public static func configure(providerToken: String, linkSections: [LinkSection]) {
814
self.providerToken = providerToken
915
self.linkSections = linkSections

Sources/LinksKit/Model/Link.swift

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
import SwiftUI
22

3+
/// Represents a link with a title, system image, and URL.
4+
///
5+
/// Use this struct to create custom links or use the provided static methods for common link types.
36
public struct Link: Identifiable {
47
public let id: UUID = UUID()
58
let title: String
69
let systemImage: String
7-
810
let url: URL
911

12+
/// Creates a new Link instance.
13+
///
14+
/// - Parameters:
15+
/// - title: The display title for the link.
16+
/// - systemImage: The name of the system image to use as an icon.
17+
/// - url: The URL the link should open.
18+
///
19+
/// Example usage:
20+
/// ```swift
21+
/// let customLink = Link(
22+
/// title: "Visit Our Website",
23+
/// systemImage: "globe",
24+
/// url: URL(string: "https://www.example.com")!
25+
/// )
26+
/// ```
1027
public init(title: String, systemImage: String, url: URL) {
1128
self.title = title
1229
self.systemImage = systemImage
@@ -15,6 +32,15 @@ public struct Link: Identifiable {
1532
}
1633

1734
extension Link {
35+
/// Creates a link to rate the app on the App Store.
36+
///
37+
/// - Parameter id: The App Store ID of your app.
38+
/// - Returns: A Link instance for rating the app.
39+
///
40+
/// Example usage:
41+
/// ```swift
42+
/// let rateLink = Link.rateTheApp(id: "1234567890")
43+
/// ```
1844
public static func rateTheApp(id: String) -> Self {
1945
Link(
2046
title: String(localized: "Rate the App", bundle: .module),
@@ -23,26 +49,81 @@ extension Link {
2349
)
2450
}
2551

52+
/// Creates a link to a Frequently Asked Questions (FAQ) page.
53+
///
54+
/// - Parameter url: The URL of your FAQ page.
55+
/// - Returns: A Link instance for the FAQ.
56+
///
57+
/// Example usage:
58+
/// ```swift
59+
/// let faqLink = Link.frequentlyAskedQuestions(url: URL(string: "https://www.example.com/faq")!)
60+
/// ```
2661
public static func frequentlyAskedQuestions(url: URL) -> Self {
2762
Link(title: String(localized: "Frequently Asked Questions (FAQ)", bundle: .module), systemImage: "questionmark.bubble", url: url)
2863
}
2964

65+
/// Creates a link to contact support via email.
66+
///
67+
/// - Parameter email: The support email address.
68+
/// - Returns: A Link instance for contacting support.
69+
///
70+
/// Example usage:
71+
/// ```swift
72+
/// let supportLink = Link.contactSupport(email: "support@example.com")
73+
/// ```
3074
public static func contactSupport(email: String) -> Self {
3175
Link(title: String(localized: "Contact Support", bundle: .module), systemImage: "envelope", url: URL(string: "mailto:\(email)")!)
3276
}
3377

78+
/// Creates a link to the privacy policy.
79+
///
80+
/// - Parameter url: The URL of your privacy policy.
81+
/// - Returns: A Link instance for the privacy policy.
82+
///
83+
/// Example usage:
84+
/// ```swift
85+
/// let privacyLink = Link.privacyPolicy(url: URL(string: "https://www.example.com/privacy")!)
86+
/// ```
3487
public static func privacyPolicy(url: URL) -> Self {
3588
Link(title: String(localized: "Privacy Policy", bundle: .module), systemImage: "lock.shield", url: url)
3689
}
3790

91+
/// Creates a link to the standard App Store Terms and Conditions.
92+
///
93+
/// - Returns: A Link instance for the App Store Terms and Conditions.
94+
///
95+
/// Example usage:
96+
/// ```swift
97+
/// let termsLink = Link.appStoreTermsAndConditions()
98+
/// ```
3899
public static func appStoreTermsAndConditions() -> Self {
39100
.termsAndConditions(url: URL(string: "https://www.apple.com/legal/internet-services/itunes/dev/stdeula/")!)
40101
}
41102

103+
/// Creates a link to custom Terms and Conditions.
104+
///
105+
/// - Parameter url: The URL of your Terms and Conditions.
106+
/// - Returns: A Link instance for the Terms and Conditions.
107+
///
108+
/// Example usage:
109+
/// ```swift
110+
/// let customTermsLink = Link.termsAndConditions(url: URL(string: "https://www.example.com/terms")!)
111+
/// ```
42112
public static func termsAndConditions(url: URL) -> Self {
43113
Link(title: String(localized: "Terms and Conditions", bundle: .module), systemImage: "text.book.closed", url: url)
44114
}
45115

116+
/// Creates a link to follow the app on a social media platform.
117+
///
118+
/// - Parameters:
119+
/// - socialPlatform: The social media platform.
120+
/// - handle: The app's handle or username on the platform.
121+
/// - Returns: A Link instance for following the app on social media.
122+
///
123+
/// Example usage:
124+
/// ```swift
125+
/// let twitterFollowLink = Link.followUsOn(socialPlatform: .twitter, handle: "YourAppHandle")
126+
/// ```
46127
public static func followUsOn(socialPlatform: SocialPlatform, handle: String) -> Self {
47128
Link(
48129
title: String(localized: "Follow us on \(socialPlatform.description)"),
@@ -51,6 +132,17 @@ extension Link {
51132
)
52133
}
53134

135+
/// Creates a link to the developer's profile on a social media platform.
136+
///
137+
/// - Parameters:
138+
/// - socialPlatform: The social media platform.
139+
/// - handle: The developer's handle or username on the platform.
140+
/// - Returns: A Link instance for the developer's social media profile.
141+
///
142+
/// Example usage:
143+
/// ```swift
144+
/// let devTwitterLink = Link.developerOn(socialPlatform: .twitter, handle: "YourDevHandle")
145+
/// ```
54146
public static func developerOn(socialPlatform: SocialPlatform, handle: String) -> Self {
55147
Link(
56148
title: String(localized: "Developer on \(socialPlatform.description)"),
@@ -59,6 +151,17 @@ extension Link {
59151
)
60152
}
61153

154+
/// Creates a link to the app's profile on a social media platform.
155+
///
156+
/// - Parameters:
157+
/// - socialPlatform: The social media platform.
158+
/// - handle: The app's handle or username on the platform.
159+
/// - Returns: A Link instance for the app's social media profile.
160+
///
161+
/// Example usage:
162+
/// ```swift
163+
/// let appInstagramLink = Link.appOn(socialPlatform: .instagram, handle: "YourAppHandle")
164+
/// ```
62165
public static func appOn(socialPlatform: SocialPlatform, handle: String) -> Self {
63166
Link(
64167
title: String(localized: "App on \(socialPlatform.description)"),
@@ -67,6 +170,24 @@ extension Link {
67170
)
68171
}
69172

173+
/// Creates a link to one of your own apps on the App Store.
174+
///
175+
/// - Parameters:
176+
/// - id: The App Store ID of the app.
177+
/// - name: The name of the app.
178+
/// - systemImage: The system image name to use as an icon.
179+
/// - campaignToken: An optional campaign token for tracking. Defaults to the main bundle identifier.
180+
/// - Returns: A Link instance for your own app.
181+
///
182+
/// Example usage:
183+
/// ```swift
184+
/// let myOtherAppLink = Link.ownApp(
185+
/// id: "1234567890",
186+
/// name: "My Other App",
187+
/// systemImage: "star.circle",
188+
/// campaignToken: "myOtherApp"
189+
/// )
190+
/// ```
70191
public static func ownApp(
71192
id: String,
72193
name: String,
@@ -80,6 +201,26 @@ extension Link {
80201
)
81202
}
82203

204+
/// Creates a link to a friend's app on the App Store.
205+
///
206+
/// - Parameters:
207+
/// - id: The App Store ID of the app.
208+
/// - name: The name of the app.
209+
/// - systemImage: The system image name to use as an icon.
210+
/// - providerToken: An optional provider token for the app's developer.
211+
/// - campaignToken: An optional campaign token for tracking. Defaults to the main bundle identifier.
212+
/// - Returns: A Link instance for a friend's app.
213+
///
214+
/// Example usage:
215+
/// ```swift
216+
/// let friendAppLink = Link.friendsApp(
217+
/// id: "0987654321",
218+
/// name: "Friend's Cool App",
219+
/// systemImage: "paintbrush",
220+
/// providerToken: "123456",
221+
/// campaignToken: "friendCoolApp"
222+
/// )
223+
/// ```
83224
public static func friendsApp(
84225
id: String,
85226
name: String,
@@ -100,6 +241,5 @@ extension Link {
100241
url: URL(string: "https://apps.apple.com/app/id\(id)?ct=\(campaignToken)&mt=8")!
101242
)
102243
}
103-
104244
}
105245
}

Sources/LinksKit/Model/LinkMenu.swift

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
import Foundation
22

3+
/// Represents a menu containing multiple link sections.
4+
///
5+
/// Use this struct to create grouped links that can be displayed in a submenu.
36
public struct LinkMenu: Identifiable {
47
public let id: UUID = UUID()
58
let title: String
69
let systemImage: String
7-
810
let linkSections: [LinkSection]
911

12+
/// Creates a new LinkMenu instance.
13+
///
14+
/// - Parameters:
15+
/// - title: The display title for the menu.
16+
/// - systemImage: The name of the system image to use as an icon.
17+
/// - linkSections: An array of LinkSection instances to include in the menu.
18+
///
19+
/// Example usage:
20+
/// ```swift
21+
/// let customMenu = LinkMenu(
22+
/// title: "Social Media",
23+
/// systemImage: "network",
24+
/// linkSections: [
25+
/// LinkSection(entries: [
26+
/// .link(Link.followUsOn(socialPlatform: .twitter, handle: "YourAppHandle")),
27+
/// .link(Link.followUsOn(socialPlatform: .instagram, handle: "YourAppHandle"))
28+
/// ])
29+
/// ]
30+
/// )
31+
/// ```
1032
public init(title: String, systemImage: String, linkSections: [LinkSection]) {
1133
self.title = title
1234
self.systemImage = systemImage
@@ -15,6 +37,18 @@ public struct LinkMenu: Identifiable {
1537
}
1638

1739
extension LinkMenu {
40+
/// Creates a menu for following the app on various social media platforms.
41+
///
42+
/// - Parameter links: An array of Link instances for different social media platforms.
43+
/// - Returns: A LinkMenu instance for following the app.
44+
///
45+
/// Example usage:
46+
/// ```swift
47+
/// let followAppMenu = LinkMenu.followTheApp(links: [
48+
/// Link.followUsOn(socialPlatform: .twitter, handle: "YourAppHandle"),
49+
/// Link.followUsOn(socialPlatform: .instagram, handle: "YourAppHandle")
50+
/// ])
51+
/// ```
1852
public static func followTheApp(links: [Link]) -> Self {
1953
LinkMenu(
2054
title: String(localized: "Follow the App", bundle: .module),
@@ -23,6 +57,18 @@ extension LinkMenu {
2357
)
2458
}
2559

60+
/// Creates a menu for following the developer on various social media platforms.
61+
///
62+
/// - Parameter links: An array of Link instances for different social media platforms.
63+
/// - Returns: A LinkMenu instance for following the developer.
64+
///
65+
/// Example usage:
66+
/// ```swift
67+
/// let followDevMenu = LinkMenu.followTheDeveloper(links: [
68+
/// Link.developerOn(socialPlatform: .twitter, handle: "YourDevHandle"),
69+
/// Link.developerOn(socialPlatform: .github, handle: "YourDevHandle")
70+
/// ])
71+
/// ```
2672
public static func followTheDeveloper(links: [Link]) -> Self {
2773
LinkMenu(
2874
title: String(localized: "Follow the Developer", bundle: .module),
@@ -31,6 +77,23 @@ extension LinkMenu {
3177
)
3278
}
3379

80+
/// Creates a menu for showcasing more apps from the developer.
81+
///
82+
/// - Parameter linkSections: An array of LinkSection instances, each potentially representing a category of apps.
83+
/// - Returns: A LinkMenu instance for more apps from the developer.
84+
///
85+
/// Example usage:
86+
/// ```swift
87+
/// let moreAppsMenu = LinkMenu.moreAppsFromDeveloper(linkSections: [
88+
/// LinkSection(title: "Productivity Apps", entries: [
89+
/// .link(Link.ownApp(id: "1234567890", name: "Todo Master", systemImage: "checklist")),
90+
/// .link(Link.ownApp(id: "0987654321", name: "Focus Timer", systemImage: "timer"))
91+
/// ]),
92+
/// LinkSection(title: "Entertainment Apps", entries: [
93+
/// .link(Link.ownApp(id: "1122334455", name: "Puzzle Quest", systemImage: "puzzle"))
94+
/// ])
95+
/// ])
96+
/// ```
3497
public static func moreAppsFromDeveloper(linkSections: [LinkSection]) -> Self {
3598
LinkMenu(
3699
title: String(localized: "More apps from Developer", bundle: .module),
@@ -39,6 +102,20 @@ extension LinkMenu {
39102
)
40103
}
41104

105+
/// Creates a menu for showcasing related apps that users might like.
106+
///
107+
/// - Parameter linkSections: An array of LinkSection instances, each potentially representing a category of related apps.
108+
/// - Returns: A LinkMenu instance for related apps.
109+
///
110+
/// Example usage:
111+
/// ```swift
112+
/// let relatedAppsMenu = LinkMenu.relatedAppsYouMightLike(linkSections: [
113+
/// LinkSection(title: "Similar Productivity Apps", entries: [
114+
/// .link(Link.friendsApp(id: "2233445566", name: "Task Pro", systemImage: "list.bullet", providerToken: "654321")),
115+
/// .link(Link.friendsApp(id: "3344556677", name: "Time Tracker", systemImage: "stopwatch", providerToken: "765432"))
116+
/// ])
117+
/// ])
118+
/// ```
42119
public static func relatedAppsYouMightLike(linkSections: [LinkSection]) -> Self {
43120
LinkMenu(
44121
title: String(localized: "Related apps you might Like", bundle: .module),

0 commit comments

Comments
 (0)