Skip to content

Commit 8b3ce88

Browse files
authored
Merge pull request #75 from etoile/swift-compatibility
Fix warnings/tests with recent macOS and add more generics annotations
2 parents 1a00121 + 7773f6a commit 8b3ce88

23 files changed

Lines changed: 230 additions & 230 deletions

CODistributedNotificationCenter.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright (C) 2014 Quentin Mathe
3+
4+
Date: July 2014
5+
License: MIT (see COPYING)
6+
*/
7+
8+
#import <Foundation/Foundation.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
/**
13+
* @group Utilities
14+
* @abstract Distributed notification center compatible with sandboxing.
15+
*
16+
* When sandboxing is enabled, posting a distributed notification results
17+
* in a normal notification.
18+
*
19+
* For non-sandboxed applications on macOS, we use
20+
* NSDistributedNotificationCenter to keep multiple store instances (using the
21+
* same UUID) in sync, accross processes and inside the current process. For
22+
* sandboxed applications on iOS or macOS, this is the same, except we don't
23+
* support the 'accross processes' case.
24+
*
25+
* We cannot ignore distributed notifications in a sandboxed app, because we
26+
* support keeping in sync two editing contexts backed by two distinct stores
27+
* objects with the same UUID.
28+
*
29+
* See also COSQLiteStore and COUndoTrackStore.
30+
**/
31+
@interface CODistributedNotificationCenter : NSObject
32+
/**
33+
* Returns the default distributed notification center.
34+
*/
35+
+ (CODistributedNotificationCenter *)defaultCenter;
36+
/**
37+
* Adds an observer for the given selector, notification name and object identifier.
38+
*/
39+
- (void)addObserver: (id)observer
40+
selector: (SEL)aSelector
41+
name: (nullable NSNotificationName)aName
42+
object: (nullable NSString *)anObject;
43+
/**
44+
* Removes an observer.
45+
*/
46+
- (void)removeObserver: (id)observer;
47+
/**
48+
* Posts a notification with the given sender and info.
49+
*
50+
* deliverImmediately is ignored, and considered as YES all the time.
51+
*/
52+
- (void)postNotificationName: (nullable NSNotificationName)aName
53+
object: (nullable NSString *)aSender
54+
userInfo: (nullable NSDictionary *)userInfo
55+
deliverImmediately: (BOOL)deliverImmediately;
56+
@end
57+
58+
NS_ASSUME_NONNULL_END

CODistributedNotificationCenter.m

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright (C) 2014 Quentin Mathe
3+
4+
Date: July 2014
5+
License: MIT (see COPYING)
6+
*/
7+
8+
#import "CODistributedNotificationCenter.h"
9+
10+
@implementation CODistributedNotificationCenter
11+
12+
static CODistributedNotificationCenter *defaultCenter = nil;
13+
14+
+ (void)initialize
15+
{
16+
if ([self class] != self)
17+
return;
18+
19+
defaultCenter = [[self alloc] init];
20+
}
21+
22+
+ (CODistributedNotificationCenter *)defaultCenter
23+
{
24+
return defaultCenter;
25+
}
26+
27+
- (void)addObserver: (id)observer
28+
selector: (SEL)aSelector
29+
name: (nullable NSNotificationName)aName
30+
object: (nullable NSString *)anObject
31+
{
32+
#if !(SANDBOXED) && !(TARGET_OS_IPHONE)
33+
[[NSDistributedNotificationCenter defaultCenter]
34+
addObserver: observer
35+
selector: aSelector
36+
name: aName
37+
object: anObject];
38+
#else
39+
[[NSNotificationCenter defaultCenter]
40+
addObserver: observer
41+
selector: aSelector
42+
name: aName
43+
object: anObject];
44+
#endif
45+
}
46+
47+
- (void)removeObserver: (id)observer {
48+
#if !(SANDBOXED) && !(TARGET_OS_IPHONE)
49+
[[NSDistributedNotificationCenter defaultCenter] removeObserver: observer];
50+
#else
51+
[[NSNotificationCenter defaultCenter] removeObserver: observer];
52+
#endif
53+
}
54+
55+
- (void)postNotificationName: (nullable NSNotificationName)aName
56+
object: (nullable NSString *)aSender
57+
userInfo: (nullable NSDictionary *)userInfo
58+
deliverImmediately: (BOOL)deliverImmediately
59+
{
60+
#if !(SANDBOXED) && !(TARGET_OS_IPHONE)
61+
[[NSDistributedNotificationCenter defaultCenter]
62+
postNotificationName: aName
63+
object: aSender
64+
userInfo: userInfo
65+
deliverImmediately: deliverImmediately];
66+
#else
67+
[[NSNotificationCenter defaultCenter]
68+
postNotificationName: aName
69+
object: aSender
70+
userInfo: userInfo];
71+
#endif
72+
}
73+
74+
@end

Core/COCrossPersistentRootDeadRelationshipCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ NS_ASSUME_NONNULL_BEGIN
5959
*
6060
* For referring object graph contexts, when unloaded or finalized, the
6161
* deallocation will trigger their removal of their inner objects from the hash
62-
* tables in the cache on 10.8 or iOS 6 or higher, but not on 10.7.
62+
* tables in the cache on 10.8 or iOS 6 or higher, which we require.
6363
*/
6464
- (void)removePath: (COPath *)aPath;
6565

Core/COCrossPersistentRootDeadRelationshipCache.m

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ - (instancetype)init
1616
{
1717
SUPERINIT;
1818
_pathToReferringObjects = [NSMutableDictionary new];
19-
#if TARGET_OS_IPHONE
2019
_referringObjectToPaths = [NSMapTable weakToStrongObjectsMapTable];
21-
#else
22-
_referringObjectToPaths = [NSMapTable mapTableWithWeakToStrongObjects];
23-
#endif
2420
return self;
2521
}
2622

@@ -35,11 +31,7 @@ - (void)addReferringObject: (COObject *)aReferrer
3531
// FIXME: If we don't ditch 10.7 support, we need a reverse mapping
3632
// from each referringObject to a path set, that can be used to remove
3733
// the referring objects when their object graph context is discarded.
38-
#if TARGET_OS_IPHONE
3934
referringObjects = [NSHashTable weakObjectsHashTable];
40-
#else
41-
referringObjects = [NSHashTable hashTableWithWeakObjects];
42-
#endif
4335

4436
_pathToReferringObjects[aPath] = referringObjects;
4537
}

Core/COEditingContext.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
#import "COCrossPersistentRootDeadRelationshipCache.h"
2424
#import "CORevisionCache.h"
2525
#import "COStoreTransaction.h"
26-
#if TARGET_OS_IPHONE
27-
#import "NSDistributedNotificationCenter.h"
28-
#endif
26+
#import "CODistributedNotificationCenter.h"
2927

3028
@implementation COEditingContext
3129

@@ -81,7 +79,7 @@ - (instancetype)initWithStore: (COSQLiteStore *)store
8179
name: COStorePersistentRootsDidChangeNotification
8280
object: _store];
8381

84-
[[NSDistributedNotificationCenter defaultCenter]
82+
[[CODistributedNotificationCenter defaultCenter]
8583
addObserver: self
8684
selector: @selector(distributedStorePersistentRootsDidChange:)
8785
name: COStorePersistentRootsDidChangeNotification
@@ -117,7 +115,7 @@ - (instancetype)init
117115

118116
- (void)dealloc
119117
{
120-
[[NSDistributedNotificationCenter defaultCenter] removeObserver: self];
118+
[[CODistributedNotificationCenter defaultCenter] removeObserver: self];
121119
[[NSNotificationCenter defaultCenter] removeObserver: self];
122120
}
123121

Core/COPrimitiveCollection.m

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ - (BOOL)isMutable
8383

8484
- (NSPointerArray *)makeBacking
8585
{
86-
#if TARGET_OS_IPHONE
8786
return [NSPointerArray strongObjectsPointerArray];
88-
#else
89-
return [NSPointerArray pointerArrayWithStrongObjects];
90-
#endif
9187
}
9288

9389
- (instancetype)init
@@ -250,7 +246,7 @@ - (void)insertObject: (id)anObject atIndex: (NSUInteger)index
250246
COThrowExceptionIfNotMutable(_permanentlyMutable, _temporaryMutable);
251247
COThrowExceptionIfOutOfBounds(self, index, YES);
252248

253-
// NSPointerArray on 10.7 doesn't allow inserting at the end using index == count, so
249+
// NSPointerArray on 10.9 (at least) doesn't allow inserting at the end using index == count, so
254250
// call addPointer in that case as a workaround.
255251
if (index == _externalIndexToBackingIndex.count)
256252
{
@@ -366,20 +362,12 @@ @implementation COUnsafeRetainedMutableArray
366362

367363
- (NSPointerArray *)makeBacking
368364
{
369-
#if TARGET_OS_IPHONE
370365
return [NSPointerArray weakObjectsPointerArray];
371-
#else
372-
return [NSPointerArray pointerArrayWithWeakObjects];
373-
#endif
374366
}
375367

376368
- (NSHashTable *)makeBackingHashTable
377369
{
378-
#if TARGET_OS_IPHONE
379370
return [NSHashTable weakObjectsHashTable];
380-
#else
381-
return [NSHashTable hashTableWithWeakObjects];
382-
#endif
383371
}
384372

385373
- (instancetype)initWithObjects: (const id[])objects count: (NSUInteger)count
@@ -672,11 +660,7 @@ @implementation COUnsafeRetainedMutableSet
672660

673661
- (NSHashTable *)makeBacking
674662
{
675-
#if TARGET_OS_IPHONE
676663
return [NSHashTable weakObjectsHashTable];
677-
#else
678-
return [NSHashTable hashTableWithWeakObjects];
679-
#endif
680664
}
681665

682666
@end

0 commit comments

Comments
 (0)