Skip to content

Commit 6ebc313

Browse files
committed
Added public init from properties for Post, Page, Logo, Icon, Tag, Category and RenderedContent
Changed URLSession.data(from) from deprecated in iOS 15 to obsoleted and added obsoleted for macOS 12 and visionOS 1 Fixed a bug with URLImageView on visionOS
1 parent 2c414b5 commit 6ebc313

8 files changed

Lines changed: 101 additions & 1 deletion

File tree

Sources/WordpressReader/Extensions/URLSession+async.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import Foundation
1010
internal extension URLSession {
1111
typealias ProjectError = WordpressReaderError
1212

13-
@available(iOS, deprecated: 15.0, message: "This extension is no longer necessary as it's built into the API")
13+
@available(iOS, obsoleted: 15.0, message: "This extension is no longer necessary as it's built into URLSession")
14+
@available(macOS, obsoleted: 12.0, message: "This extension is no longer necessary as it's built into URLSession")
15+
@available(visionOS, obsoleted: 1.0, message: "This extension is no longer necessary as it's built into URLSession")
1416
/// Retrieves the contents of a URL and delivers the data asynchronously.
1517
/// - Parameter url: The URL to retrieve
1618
/// - Returns: An asynchronously-delivered tuple that contains the URL contents as a Data instance, and a URLResponse.

Sources/WordpressReader/RenderedContent.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ public struct RenderedContent: Codable, Hashable, Equatable, ParameterLabels {
1313

1414
/// String containing HTML code representing the rendered content on Wordpress.
1515
public var rendered: String
16+
17+
/// Create rendered content from a string. Useful for generating sample content.
18+
/// - Parameter rendered: String containing HTML code representing the rendered content on Wordpress.
19+
public init(rendered: String) {
20+
self.rendered = rendered
21+
}
1622
}
1723

1824
extension RenderedContent {

Sources/WordpressReader/WordpressCategory.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,22 @@ public struct WordpressCategory: WordpressTaxonomy {
2121
public var name: String
2222
public var description: String
2323

24+
/// Create a category using properties. Useful for generating sample content.
25+
public init(
26+
id: Int,
27+
link: String,
28+
slug: String,
29+
count: Int,
30+
name: String,
31+
description: String
32+
) {
33+
self.id = id
34+
self.link = link
35+
self.slug = slug
36+
self.count = count
37+
self.name = name
38+
self.description = description
39+
}
40+
2441
public static let urlComponent = "categories"
2542
}

Sources/WordpressReader/WordpressIcon.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ public struct WordpressIcon: Codable, Hashable, Equatable, ParameterLabels {
1515
public var img: String
1616
/// Appears to be a duplicate of the img property?
1717
public var ico: String
18+
19+
/// Create a post using properties. Useful for generating sample content.
20+
public init(img: String, ico: String) {
21+
self.img = img
22+
self.ico = ico
23+
}
1824
}

Sources/WordpressReader/WordpressLogo.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ public struct WordpressLogo: Codable, Identifiable, Hashable, Equatable, Paramet
1616

1717
/// URL to access the logo image.
1818
public var url: String
19+
20+
/// Create a logo using properties. Useful for generating sample content.
21+
public init(id: Int, url: String) {
22+
self.id = id
23+
self.url = url
24+
}
1925
}

Sources/WordpressReader/WordpressPage.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,26 @@ public struct WordpressPage: WordpressContent {
2424
public var content: RenderedContent
2525
public var excerpt: RenderedContent
2626

27+
/// Create a page using properties. Useful for generating sample content.
28+
public init(
29+
id: Int,
30+
link: String,
31+
slug: String,
32+
date_gmt: Date,
33+
modified_gmt: Date,
34+
title: RenderedContent,
35+
content: RenderedContent,
36+
excerpt: RenderedContent
37+
) {
38+
self.id = id
39+
self.link = link
40+
self.slug = slug
41+
self.date_gmt = date_gmt
42+
self.modified_gmt = modified_gmt
43+
self.title = title
44+
self.content = content
45+
self.excerpt = excerpt
46+
}
47+
2748
public static let urlComponent = "pages"
2849
}

Sources/WordpressReader/WordpressPost.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,30 @@ public struct WordpressPost: WordpressContent {
3030
/// An array of unique identifiers for WordpressTag objects
3131
public var tags: [Int]
3232

33+
/// Create a post using properties. Useful for generating sample content.
34+
public init(
35+
id: Int,
36+
link: String,
37+
slug: String,
38+
date_gmt: Date,
39+
modified_gmt: Date,
40+
title: RenderedContent,
41+
content: RenderedContent,
42+
excerpt: RenderedContent,
43+
categories: [Int],
44+
tags: [Int]
45+
) {
46+
self.id = id
47+
self.link = link
48+
self.slug = slug
49+
self.date_gmt = date_gmt
50+
self.modified_gmt = modified_gmt
51+
self.title = title
52+
self.content = content
53+
self.excerpt = excerpt
54+
self.categories = categories
55+
self.tags = tags
56+
}
57+
3358
public static let urlComponent = "posts"
3459
}

Sources/WordpressReader/WordpressTag.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,22 @@ public struct WordpressTag: WordpressTaxonomy {
2121
public var name: String
2222
public var description: String
2323

24+
/// Create a tag using properties. Useful for generating sample content.
25+
public init(
26+
id: Int,
27+
link: String,
28+
slug: String,
29+
count: Int,
30+
name: String,
31+
description: String
32+
) {
33+
self.id = id
34+
self.link = link
35+
self.slug = slug
36+
self.count = count
37+
self.name = name
38+
self.description = description
39+
}
40+
2441
public static let urlComponent = "tags"
2542
}

0 commit comments

Comments
 (0)