Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 09cd373

Browse files
committed
Update WordPressComRESTAPIInterfacing to generate Any in Swift
1 parent e8b69e3 commit 09cd373

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

Sources/WordPressKit/WordPressAPI/WordPressComRESTAPIInterfacing.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66

77
@property (strong, nonatomic, readonly) NSURL * _Nonnull baseURL;
88

9+
/// - Note: `parameters` has `id` instead of the more common `NSObject *` as its value type so it will convert to `AnyObject` in Swift.
10+
/// In Swift, it's simpler to work with `AnyObject` than with `NSObject`. For example `"abc" as AnyObject` over `"abc" as NSObject`.
911
- (NSProgress * _Nullable)get:(NSString * _Nonnull)URLString
10-
parameters:(NSDictionary<NSString *, NSObject *> * _Nullable)parameters
12+
parameters:(NSDictionary<NSString *, id> * _Nullable)parameters
1113
success:(void (^ _Nonnull)(id _Nonnull, NSHTTPURLResponse * _Nullable))success
1214
failure:(void (^ _Nonnull)(NSError * _Nonnull, NSHTTPURLResponse * _Nullable))failure;
1315

16+
/// - Note: `parameters` has `id` instead of the more common `NSObject *` as its value type so it will convert to `AnyObject` in Swift.
17+
/// In Swift, it's simpler to work with `AnyObject` than with `NSObject`. For example `"abc" as AnyObject` over `"abc" as NSObject`.
1418
- (NSProgress * _Nullable)post:(NSString * _Nonnull)URLString
15-
parameters:(NSDictionary<NSString *, NSObject *> * _Nullable)parameters
19+
parameters:(NSDictionary<NSString *, id> * _Nullable)parameters
1620
success:(void (^ _Nonnull)(id _Nonnull, NSHTTPURLResponse * _Nullable))success
1721
failure:(void (^ _Nonnull)(NSError * _Nonnull, NSHTTPURLResponse * _Nullable))failure;
1822

Sources/WordPressKit/WordPressAPI/WordPressComRestApi.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -615,20 +615,34 @@ extension WordPressComRestApi: WordPressComRESTAPIInterfacing {
615615
// The same applies for the other methods below.
616616
public func get(
617617
_ URLString: String,
618-
parameters: [String: NSObject]?,
618+
parameters: [String: Any]?,
619619
success: @escaping (Any, HTTPURLResponse?) -> Void,
620620
failure: @escaping (any Error, HTTPURLResponse?) -> Void
621621
) -> Progress? {
622-
GET(URLString, parameters: parameters, success: success, failure: failure)
622+
GET(
623+
URLString,
624+
// It's possible `WordPressComRestApi` could be updated to use `[String: Any]` instead.
625+
// But leaving that investigation for later.
626+
parameters: parameters as? [String: AnyObject],
627+
success: success,
628+
failure: failure
629+
)
623630
}
624631

625632
public func post(
626633
_ URLString: String,
627-
parameters: [String: NSObject]?,
634+
parameters: [String: Any]?,
628635
success: @escaping (Any, HTTPURLResponse?) -> Void,
629636
failure: @escaping (any Error, HTTPURLResponse?) -> Void
630637
) -> Progress? {
631-
POST(URLString, parameters: parameters, success: success, failure: failure)
638+
POST(
639+
URLString,
640+
// It's possible `WordPressComRestApi` could be updated to use `[String: Any]` instead.
641+
// But leaving that investigation for later.
642+
parameters: parameters as? [String: AnyObject],
643+
success: success,
644+
failure: failure
645+
)
632646
}
633647

634648
public func multipartPOST(

0 commit comments

Comments
 (0)