OSDN Git Service

KVOのコンテクストを専用のオブジェクトに変更した
authormasakih <masakih@users.sourceforge.jp>
Sun, 24 Apr 2016 13:52:51 +0000 (22:52 +0900)
committermasakih <masakih@users.sourceforge.jp>
Sun, 24 Apr 2016 13:52:51 +0000 (22:52 +0900)
KCD/HMExternalBrowserWindowController.m
KCD/HMFleet.m
KCD/HMSuppliesView.m

index 35119aa..3b8036d 100644 (file)
@@ -12,6 +12,7 @@
 #import "HMBookmarkManager.h"
 #import "HMBookmarkListViewController.h"
 
+static void *WebViewContext = &WebViewContext;
 
 
 @interface HMExternalBrowserWindowController () <HMBookmarkListViewControllerDelegate, NSAnimationDelegate, WebFrameLoadDelegate>
        [self.webView addObserver:self
                                   forKeyPath:@"canGoBack"
                                          options:0
-                                         context:(__bridge void *)(self.webView)];
+                                         context:WebViewContext];
        [self.webView addObserver:self
                                   forKeyPath:@"canGoForward"
                                          options:0
-                                         context:(__bridge void *)(self.webView)];
+                                         context:WebViewContext];
        
        HMAppDelegate *appDelegate = [[NSApplication sharedApplication] delegate];
        [self.webView setApplicationNameForUserAgent:appDelegate.appNameForUserAgent];
@@ -68,8 +69,7 @@
 
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
 {
-       id contextObject = (__bridge id)(context);
-       if(self.webView == contextObject) {
+       if(context == WebViewContext) {
                if([keyPath isEqualToString:@"canGoBack"]) {
                        [self.goSegment setEnabled:self.webView.canGoBack forSegment:0];
                }
index 0b4ae3a..32c8c32 100644 (file)
 #import "HMKCDeck+Extension.h"
 #import "HMKCShipObject+Extensions.h"
 
+
+
+static void *DeckContext = &DeckContext;
+static void *ShipContext = &ShipContext;
+
 @interface HMFleet ()
 @property (strong) NSNumber *fleetNumber;
 @property (strong) NSObjectController *deckController;
@@ -56,7 +61,7 @@
                        [_deckController addObserver:self
                                                          forKeyPath:key
                                                                 options:0
-                                                                context:(__bridge void * _Nullable)(_deck)];
+                                                                context:DeckContext];
                }
        }
        
 
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
 {
-       id obj = (__bridge id)(context);
-       if(obj == _deck) {
+       if(context == DeckContext) {
                
                for(HMKCShipObject *ship in _ships) {
                        for(NSString *key in self.shipObserveKeys) {
                                [ship addObserver:self
                                           forKeyPath:key
                                                  options:0
-                                                 context:(__bridge void * _Nullable)(_ships)];
+                                                 context:ShipContext];
                        }
                }
                
                return;
        }
        
-       if(obj == _ships) {
+       if(context == ShipContext) {
                if([keyPath isEqualToString:@"sakuteki_0"]) {
                        [self willChangeValueForKey:@"totalSakuteki"];
                        [self didChangeValueForKey:@"totalSakuteki"];
index e0ce11d..d6102e8 100644 (file)
 #import "HMKCShipObject+Extensions.h"
 
 
+
+static void *ShipStatusContext = &ShipStatusContext;
+
+
 @interface HMSuppliesView ()
 @property (nonatomic, strong) HMSuppliesCell *suppliesCell;
 @end
        [self.suppliesCell.shipStatus addObserver:self
                                                                   forKeyPath:@"fuel"
                                                                          options:NSKeyValueObservingOptionNew
-                                                                         context:(__bridge void *)(self.suppliesCell.shipStatus)];
+                                                                         context:ShipStatusContext];
        [self.suppliesCell.shipStatus addObserver:self
                                                                   forKeyPath:@"maxFuel"
                                                                          options:NSKeyValueObservingOptionNew
-                                                                         context:(__bridge void *)(self.suppliesCell.shipStatus)];
+                                                                         context:ShipStatusContext];
        [self.suppliesCell.shipStatus addObserver:self
                                                                   forKeyPath:@"bull"
                                                                          options:NSKeyValueObservingOptionNew
-                                                                         context:(__bridge void *)(self.suppliesCell.shipStatus)];
+                                                                         context:ShipStatusContext];
        [self.suppliesCell.shipStatus addObserver:self
                                                                   forKeyPath:@"maxBull"
                                                                          options:NSKeyValueObservingOptionNew
-                                                                         context:(__bridge void *)(self.suppliesCell.shipStatus)];
+                                                                         context:ShipStatusContext];
        
        [self setNeedsDisplay];
 }
@@ -73,9 +77,7 @@
 
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
 {
-       HMKCShipObject *status = (__bridge HMKCShipObject *)(context);
-       
-       if(status == self.suppliesCell.shipStatus) {
+       if(context ==ShipStatusContext) {
                [self setNeedsDisplay];
                return;
        }