diff --git a/CoreStoreTests/BridgingTests.m b/CoreStoreTests/BridgingTests.m index 5d5f99e..886bc40 100644 --- a/CoreStoreTests/BridgingTests.m +++ b/CoreStoreTests/BridgingTests.m @@ -42,6 +42,14 @@ XCTAssertEqual(CSLocalStorageOptionsAllowSynchronousLightweightMigration, 4); } +- (void)test_ThatKeyPaths_AreCorrect { + + XCTAssertEqualObjects(CSKeyPath(TestEntity1, testNumber), @"testNumber"); + XCTAssertEqualObjects(CSKeyPath(TestEntity1, testString), @"testString"); + XCTAssertEqualObjects(CSKeyPathOperator(count, TestEntity1, testString), @"@count.testString"); + XCTAssertEqualObjects(CSKeyPathOperator(max, TestEntity1, testNumber), @"@max.testNumber"); +} + - (void)test_ThatFromClauses_BridgeCorrectly { { diff --git a/Sources/ObjectiveC/CoreStoreBridge.h b/Sources/ObjectiveC/CoreStoreBridge.h index 1105a00..bf8faf3 100644 --- a/Sources/ObjectiveC/CoreStoreBridge.h +++ b/Sources/ObjectiveC/CoreStoreBridge.h @@ -43,7 +43,25 @@ #define CORESTORE_RETURNS_RETAINED __attribute__((ns_returns_retained)) -// MARK: - CSFrom +#pragma mark - KeyPath Utilities + +#define CSKeyPath(type, property) ({ \ + type *_je_keypath_dummy __attribute__((unused)); \ + typeof(_je_keypath_dummy.property) _je_keypath_dummy_property __attribute__((unused)); \ + @#property; \ +}) + +#define CSKeyPathOperator(operator, type, property) ({ \ + type *_je_keypath_dummy __attribute__((unused)); \ + typeof(_je_keypath_dummy.property) _je_keypath_dummy_property __attribute__((unused)); \ + @"@" #operator "." #property; \ +}) + + +#pragma mark - Clauses + + +#pragma mark CSFrom @class CSFrom; @@ -130,7 +148,7 @@ CORESTORE_EXTERN CORESTORE_OVERLOADABLE CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass, NSArray *_Nonnull configurations) CORESTORE_RETURNS_RETAINED; -// MARK: - CSGroupBy +#pragma mark CSGroupBy @class CSGroupBy; @@ -174,7 +192,7 @@ CORESTORE_EXTERN CORESTORE_OVERLOADABLE CSGroupBy *_Nonnull CSGroupByKeyPaths(NSArray *_Nonnull keyPaths) CORESTORE_RETURNS_RETAINED; -// MARK: - CSInto +#pragma mark CSInto @class CSInto; @@ -239,7 +257,7 @@ CORESTORE_OVERLOADABLE CSInto *_Nonnull CSIntoClass(Class _Nonnull entityClass, NSString *_Nonnull configuration) CORESTORE_RETURNS_RETAINED; -// MARK: - CSOrderBy +#pragma mark CSOrderBy @class CSOrderBy; @@ -339,7 +357,7 @@ CORESTORE_EXTERN CORESTORE_OVERLOADABLE CSOrderBy *_Nonnull CSOrderByKeys(NSArray *_Nonnull sortDescriptors) CORESTORE_RETURNS_RETAINED; -// MARK: - CSSelect +#pragma mark CSSelect @class CSSelect; @class CSSelectTerm; @@ -465,7 +483,7 @@ CORESTORE_EXTERN CSSelect *_Nonnull CSSelectObjectID() CORESTORE_RETURNS_RETAINED; -// MARK: - CSTweak +#pragma mark CSTweak @class CSTweak; @@ -486,7 +504,7 @@ CORESTORE_EXTERN CORESTORE_OVERLOADABLE CSTweak *_Nonnull CSTweakRequest(void (^_Nonnull block)(NSFetchRequest *_Nonnull fetchRequest)) CORESTORE_RETURNS_RETAINED; -// MARK: - CSWhere +#pragma mark CSWhere @class CSWhere; diff --git a/Sources/ObjectiveC/CoreStoreBridge.m b/Sources/ObjectiveC/CoreStoreBridge.m index 93d3f0c..6c770c5 100644 --- a/Sources/ObjectiveC/CoreStoreBridge.m +++ b/Sources/ObjectiveC/CoreStoreBridge.m @@ -43,7 +43,10 @@ #endif -// MARK: - CSFrom + +#pragma mark - Clauses + +#pragma mark CSFrom CORESTORE_OVERLOADABLE CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass) CORESTORE_RETURNS_RETAINED { @@ -70,7 +73,7 @@ CSFrom *_Nonnull CSFromClass(Class _Nonnull entityClass, NSArray *_Nonnull c } -// MARK: - CSGroupBy +#pragma mark CSGroupBy CSGroupBy *_Nonnull CSGroupByKeyPath(NSString *_Nonnull keyPath) CORESTORE_RETURNS_RETAINED { @@ -102,7 +105,7 @@ CSGroupBy *_Nonnull CSGroupByKeyPaths(NSArray *_Nonnull keyPaths) CO } -// MARK: - CSInto +#pragma mark CSInto CORESTORE_OVERLOADABLE CSInto *_Nonnull CSIntoClass(Class _Nonnull entityClass) CORESTORE_RETURNS_RETAINED { @@ -123,7 +126,7 @@ CSInto *_Nonnull CSIntoClass(Class _Nonnull entityClass, NSString *_Nonnull conf } -// MARK: - CSOrderBy +#pragma mark CSOrderBy @class CSOrderBy; @@ -167,7 +170,7 @@ CSOrderBy *_Nonnull CSOrderByKeys(NSArray *_Nonnull sortDesc } -// MARK: - CSSelect +#pragma mark CSSelect CSSelect *_Nonnull CSSelectNumber(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RETURNS_RETAINED { @@ -200,7 +203,7 @@ CSSelect *_Nonnull CSSelectObjectID() CORESTORE_RETURNS_RETAINED { } -// MARK: - CSTweak +#pragma mark CSTweak CORESTORE_OVERLOADABLE CSTweak *_Nonnull CSTweakRequest(void (^_Nonnull block)(NSFetchRequest *_Nonnull fetchRequest)) CORESTORE_RETURNS_RETAINED { @@ -209,7 +212,7 @@ CSTweak *_Nonnull CSTweakRequest(void (^_Nonnull block)(NSFetchRequest *_Nonnull } -// MARK: - CSWhere +#pragma mark CSWhere CSWhere *_Nonnull CSWhereValue(BOOL value) CORESTORE_RETURNS_RETAINED {