11import 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.
36public 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
1734extension 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}
0 commit comments