Skip to content

Commit 02a6538

Browse files
Merge pull request #5325 from wordpress-mobile/cleanup/add-nullability-to-blog-2
Adds nullability information to Blog.h
2 parents 28b730c + 84af4b6 commit 02a6538

12 files changed

+92
-87
lines changed

WordPress/Classes/Models/Blog.h

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#import <CoreData/CoreData.h>
44
#import "JetpackState.h"
55

6+
NS_ASSUME_NONNULL_BEGIN
7+
68
@class BlogSettings;
79
@class WPAccount;
810
@class WordPressComApi;
@@ -54,53 +56,53 @@ typedef NS_ENUM(NSInteger, SiteVisibility) {
5456

5557
@interface Blog : NSManagedObject
5658

57-
@property (nonatomic, strong, readwrite) NSNumber *blogID __deprecated_msg("Use dotComID instead");
58-
@property (nonatomic, strong, readwrite) NSNumber *dotComID;
59-
@property (nonatomic, strong, readwrite) NSString *xmlrpc;
60-
@property (nonatomic, strong, readwrite) NSString *apiKey;
61-
@property (nonatomic, strong, readwrite) NSNumber *hasOlderPosts;
62-
@property (nonatomic, strong, readwrite) NSNumber *hasOlderPages;
63-
@property (nonatomic, strong, readwrite) NSSet *posts;
64-
@property (nonatomic, strong, readwrite) NSSet *categories;
65-
@property (nonatomic, strong, readwrite) NSSet *tags;
66-
@property (nonatomic, strong, readwrite) NSSet *comments;
67-
@property (nonatomic, strong, readwrite) NSSet *connections;
68-
@property (nonatomic, strong, readwrite) NSSet *themes;
69-
@property (nonatomic, strong, readwrite) NSSet *media;
70-
@property (nonatomic, strong, readwrite) NSOrderedSet *menus;
71-
@property (nonatomic, strong, readwrite) NSOrderedSet *menuLocations;
72-
@property (nonatomic, strong, readwrite) NSString *currentThemeId;
59+
@property (nonatomic, strong, readwrite, nullable) NSNumber *blogID __deprecated_msg("Use dotComID instead");
60+
@property (nonatomic, strong, readwrite, nullable) NSNumber *dotComID;
61+
@property (nonatomic, strong, readwrite, nullable) NSString *xmlrpc;
62+
@property (nonatomic, strong, readwrite, nullable) NSString *apiKey;
63+
@property (nonatomic, strong, readwrite, nullable) NSNumber *hasOlderPosts;
64+
@property (nonatomic, strong, readwrite, nullable) NSNumber *hasOlderPages;
65+
@property (nonatomic, strong, readwrite, nullable) NSSet *posts;
66+
@property (nonatomic, strong, readwrite, nullable) NSSet *categories;
67+
@property (nonatomic, strong, readwrite, nullable) NSSet *tags;
68+
@property (nonatomic, strong, readwrite, nullable) NSSet *comments;
69+
@property (nonatomic, strong, readwrite, nullable) NSSet *connections;
70+
@property (nonatomic, strong, readwrite, nullable) NSSet *themes;
71+
@property (nonatomic, strong, readwrite, nullable) NSSet *media;
72+
@property (nonatomic, strong, readwrite, nullable) NSOrderedSet *menus;
73+
@property (nonatomic, strong, readwrite, nullable) NSOrderedSet *menuLocations;
74+
@property (nonatomic, strong, readwrite, nullable) NSString *currentThemeId;
7375
@property (nonatomic, assign, readwrite) BOOL isSyncingPosts;
7476
@property (nonatomic, assign, readwrite) BOOL isSyncingPages;
7577
@property (nonatomic, assign, readwrite) BOOL isSyncingMedia;
76-
@property (nonatomic, strong, readwrite) NSDate *lastPostsSync;
77-
@property (nonatomic, strong, readwrite) NSDate *lastPagesSync;
78-
@property (nonatomic, strong, readwrite) NSDate *lastCommentsSync;
79-
@property (nonatomic, strong, readwrite) NSDate *lastStatsSync;
80-
@property (nonatomic, strong, readwrite) NSString *lastUpdateWarning;
78+
@property (nonatomic, strong, readwrite, nullable) NSDate *lastPostsSync;
79+
@property (nonatomic, strong, readwrite, nullable) NSDate *lastPagesSync;
80+
@property (nonatomic, strong, readwrite, nullable) NSDate *lastCommentsSync;
81+
@property (nonatomic, strong, readwrite, nullable) NSDate *lastStatsSync;
82+
@property (nonatomic, strong, readwrite, nullable) NSString *lastUpdateWarning;
8183
@property (nonatomic, assign, readwrite) BOOL visible;
82-
@property (nonatomic, weak, readwrite) NSNumber *isActivated;
83-
@property (nonatomic, strong, readwrite) NSDictionary *options;
84-
@property (nonatomic, strong, readwrite) NSSet *postTypes;
85-
@property (nonatomic, strong, readwrite) NSDictionary *postFormats;
86-
@property (nonatomic, strong, readwrite) WPAccount *account;
87-
@property (nonatomic, strong, readwrite) WPAccount *jetpackAccount;
88-
@property (nonatomic, strong, readwrite) WPAccount *accountForDefaultBlog;
84+
@property (nonatomic, weak, readwrite, nullable) NSNumber *isActivated;
85+
@property (nonatomic, strong, readwrite, nullable) NSDictionary *options;
86+
@property (nonatomic, strong, readwrite, nullable) NSSet *postTypes;
87+
@property (nonatomic, strong, readwrite, nullable) NSDictionary *postFormats;
88+
@property (nonatomic, strong, readwrite, nullable) WPAccount *account;
89+
@property (nonatomic, strong, readwrite, nullable) WPAccount *jetpackAccount;
90+
@property (nonatomic, strong, readwrite, nullable) WPAccount *accountForDefaultBlog;
8991
@property (nonatomic, assign, readwrite) BOOL videoPressEnabled;
9092
@property (nonatomic, assign, readwrite) BOOL isMultiAuthor;
9193
@property (nonatomic, assign, readwrite) BOOL isHostedAtWPcom;
92-
@property (nonatomic, strong, readwrite) NSString *icon;
94+
@property (nonatomic, strong, readwrite, nullable) NSString *icon;
9395
@property (nonatomic, assign, readwrite) SiteVisibility siteVisibility;
94-
@property (nonatomic, strong, readwrite) NSNumber *planID;
95-
@property (nonatomic, strong, readwrite) NSSet *sharingButtons;
96-
@property (nonatomic, strong, readwrite) NSDictionary *capabilities;
96+
@property (nonatomic, strong, readwrite, nullable) NSNumber *planID;
97+
@property (nonatomic, strong, readwrite, nullable) NSSet *sharingButtons;
98+
@property (nonatomic, strong, readwrite, nullable) NSDictionary *capabilities;
9799

98100

99101
/**
100102
* @details Maps to a BlogSettings instance, which contains a collection of the available preferences,
101103
* and their values.
102104
*/
103-
@property (nonatomic, strong, readwrite) BlogSettings *settings;
105+
@property (nonatomic, strong, readwrite, nullable) BlogSettings *settings;
104106

105107
/**
106108
* @details Flags whether the current user is an admin on the blog.
@@ -112,23 +114,23 @@ typedef NS_ENUM(NSInteger, SiteVisibility) {
112114
*
113115
* @warn For WordPress.com or Jetpack Managed sites this will be nil. Use usernameForSite instead
114116
*/
115-
@property (nonatomic, strong, readwrite) NSString *username;
116-
@property (nonatomic, strong, readwrite) NSString *password;
117+
@property (nonatomic, strong, readwrite, nullable) NSString *username;
118+
@property (nonatomic, strong, readwrite, nullable) NSString *password;
117119

118120

119121
// Readonly Properties
120-
@property (nonatomic, weak, readonly) NSArray *sortedPostFormatNames;
121-
@property (nonatomic, weak, readonly) NSArray *sortedPostFormats;
122-
@property (nonatomic, strong, readonly) WPXMLRPCClient *api;
123-
@property (nonatomic, weak, readonly) NSString *version;
124-
@property (nonatomic, strong, readonly) NSString *authToken;
125-
@property (nonatomic, strong, readonly) NSSet *allowedFileTypes;
126-
@property (nonatomic, copy, readonly) NSString *usernameForSite;
122+
@property (nonatomic, weak, readonly, nullable) NSArray *sortedPostFormatNames;
123+
@property (nonatomic, weak, readonly, nullable) NSArray *sortedPostFormats;
124+
@property (nonatomic, strong, readonly, nullable) WPXMLRPCClient *api;
125+
@property (nonatomic, weak, readonly, nullable) NSString *version;
126+
@property (nonatomic, strong, readonly, nullable) NSString *authToken;
127+
@property (nonatomic, strong, readonly, nullable) NSSet *allowedFileTypes;
128+
@property (nonatomic, copy, readonly, nullable) NSString *usernameForSite;
127129

128130
/**
129131
* @details Contains the Jetpack state. Returns nil if the blog options haven't been downloaded yet
130132
*/
131-
@property (nonatomic, strong, readonly) JetpackState *jetpack;
133+
@property (nonatomic, strong, readonly, nullable) JetpackState *jetpack;
132134

133135

134136
/**
@@ -137,23 +139,23 @@ typedef NS_ENUM(NSInteger, SiteVisibility) {
137139

138140
// User to display the blog url to the user (IDN decoded, no http:)
139141
// wp.koke.me/sub
140-
@property (weak, readonly) NSString *displayURL;
142+
@property (weak, readonly, nullable) NSString *displayURL;
141143
// alias of displayURL
142144
// kept for compatibilty, used as a key to store passwords
143-
@property (weak, readonly) NSString *hostURL;
144-
@property (weak, readonly) NSString *homeURL;
145+
@property (weak, readonly, nullable) NSString *hostURL;
146+
@property (weak, readonly, nullable) NSString *homeURL;
145147
// http://wp.koke.me/sub
146-
@property (nonatomic, strong) NSString *url;
148+
@property (nonatomic, strong, nullable) NSString *url;
147149
// Used for reachability checks (IDN encoded)
148150
// wp.koke.me
149-
@property (weak, readonly) NSString *hostname;
151+
@property (weak, readonly, nullable) NSString *hostname;
150152

151-
@property (weak, readonly) NSString *defaultPostFormatText;
153+
@property (weak, readonly, nullable) NSString *defaultPostFormatText;
152154

153155
#pragma mark - Blog information
154156
- (BOOL)isPrivate;
155-
- (NSArray *)sortedCategories;
156-
- (id)getOptionValue:(NSString *) name;
157+
- (nullable NSArray *)sortedCategories;
158+
- (nullable id)getOptionValue:(NSString *) name;
157159
- (NSString *)loginUrl;
158160
- (NSString *)urlWithPath:(NSString *)path;
159161
- (NSString *)adminUrlWithPath:(NSString *)path;
@@ -171,7 +173,7 @@ typedef NS_ENUM(NSInteger, SiteVisibility) {
171173
*
172174
* @return a string with the post format description and if no description was found the postFormatCode sent.
173175
*/
174-
- (NSString *)postFormatTextFromSlug:(NSString *)postFormatSlug;
176+
- (nullable NSString *)postFormatTextFromSlug:(NSString *)postFormatSlug;
175177
/**
176178
Returns a human readable description for logging
177179
@@ -190,6 +192,8 @@ typedef NS_ENUM(NSInteger, SiteVisibility) {
190192
191193
@return a WordPressComApi object if available
192194
*/
193-
- (WordPressComApi *)restApi;
195+
- (nullable WordPressComApi *)restApi;
194196

195197
@end
198+
199+
NS_ASSUME_NONNULL_END

WordPress/Classes/Services/PeopleService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct PeopleService {
2323
}
2424

2525
remote = PeopleRemote(api: api)
26-
siteID = blog.dotComID as Int
26+
siteID = blog.dotComID as! Int
2727
}
2828

2929

WordPress/Classes/Services/SharingService.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class SharingService : LocalCoreDataService
6666
guard let remote = remoteForBlog(blog) else {
6767
return
6868
}
69-
remote.getPublicizeConnections(blog.dotComID, success: {(remoteConnections:[RemotePublicizeConnection]) in
69+
remote.getPublicizeConnections(blog.dotComID!, success: {(remoteConnections:[RemotePublicizeConnection]) in
7070

7171
// Process the results
7272
self.mergePublicizeConnectionsForBlog(blogObjectID, remoteConnections: remoteConnections, onComplete: success)
@@ -97,7 +97,7 @@ public class SharingService : LocalCoreDataService
9797
guard let remote = remoteForBlog(blog) else {
9898
return
9999
}
100-
let dotComID = blog.dotComID
100+
let dotComID = blog.dotComID!
101101
remote.createPublicizeConnection(dotComID,
102102
keyringConnectionID: keyring.keyringID,
103103
externalUserID: externalUserID,
@@ -546,7 +546,7 @@ public class SharingService : LocalCoreDataService
546546
return
547547
}
548548

549-
remote.getSharingButtonsForSite(blog.dotComID,
549+
remote.getSharingButtonsForSite(blog.dotComID!,
550550
success: { (remoteButtons:[RemoteSharingButton]) in
551551
self.mergeSharingButtonsForBlog(blogObjectID, remoteSharingButtons: remoteButtons, onComplete: success)
552552
},
@@ -570,7 +570,7 @@ public class SharingService : LocalCoreDataService
570570
guard let remote = remoteForBlog(blog) else {
571571
return
572572
}
573-
remote.updateSharingButtonsForSite(blog.dotComID,
573+
remote.updateSharingButtonsForSite(blog.dotComID!,
574574
sharingButtons: remoteShareButtonsFromShareButtons(sharingButtons),
575575
success: { (remoteButtons:[RemoteSharingButton]) in
576576
self.mergeSharingButtonsForBlog(blogObjectID, remoteSharingButtons: remoteButtons, onComplete: success)

WordPress/Classes/Services/SiteManagementService.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class SiteManagementService : LocalCoreDataService
2727
guard let remote = siteManagementServiceRemoteForBlog(blog) else {
2828
return
2929
}
30-
remote.deleteSite(blog.dotComID,
30+
remote.deleteSite(blog.dotComID!,
3131
success: {
3232
self.managedObjectContext.performBlock {
3333
let blogService = BlogService(managedObjectContext: self.managedObjectContext)
@@ -56,7 +56,7 @@ public class SiteManagementService : LocalCoreDataService
5656
guard let remote = siteManagementServiceRemoteForBlog(blog) else {
5757
return
5858
}
59-
remote.exportContent(blog.dotComID,
59+
remote.exportContent(blog.dotComID!,
6060
success: {
6161
success?()
6262
},
@@ -76,7 +76,7 @@ public class SiteManagementService : LocalCoreDataService
7676
guard let remote = siteManagementServiceRemoteForBlog(blog) else {
7777
return
7878
}
79-
remote.getActivePurchases(blog.dotComID,
79+
remote.getActivePurchases(blog.dotComID!,
8080
success: { purchases in
8181
success?(purchases)
8282
},

WordPress/Classes/ViewRelated/Blog/DiscussionSettingsViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ public class DiscussionSettingsViewController : UITableViewController
601601

602602
// MARK: - Computed Properties
603603
private var settings : BlogSettings {
604-
return blog.settings
604+
return blog.settings!
605605
}
606606

607607
// MARK: - Typealiases

WordPress/Classes/ViewRelated/Blog/LanguageViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class LanguageViewController : UITableViewController
8686

8787
// MARK: - Private Methods
8888
private func configureTableViewCell(cell: UITableViewCell) {
89-
let languageId = blog.settings.languageID.integerValue
89+
let languageId = blog.settings!.languageID.integerValue
9090
cell.textLabel?.text = NSLocalizedString("Language", comment: "Language of the current blog")
9191
cell.detailTextLabel?.text = languageDatabase.nameForLanguageWithId(languageId)
9292
}
@@ -106,7 +106,7 @@ public class LanguageViewController : UITableViewController
106106
// Setup ListPickerViewController
107107
let listViewController = SettingsListPickerViewController(headers: headers, titles: titles, subtitles: subtitles, values: values)
108108
listViewController.title = NSLocalizedString("Site Language", comment: "Title for the Language Picker View")
109-
listViewController.selectedValue = blog.settings.languageID
109+
listViewController.selectedValue = blog.settings!.languageID
110110
listViewController.onChange = { [weak self] (selected: AnyObject) in
111111
guard let newLanguageID = selected as? NSNumber else {
112112
return

0 commit comments

Comments
 (0)