Skip to content

Commit

Permalink
Rename where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Sep 30, 2016
1 parent fa3e424 commit 669a812
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 82 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Check https://github.com/hyperoslo/Sync/releases for more information.
Check https://github.com/SyncDB/Sync/releases for more information.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
GitHub Issues is for reporting bugs, discussing features and general feedback in **Sync**. Be sure to check our [documentation](http://cocoadocs.org/docsets/Sync), [FAQ](https://github.com/hyperoslo/Sync/wiki/FAQ) and [past issues](https://github.com/hyperoslo/Sync/issues?state=closed) before opening any new issues.
GitHub Issues is for reporting bugs, discussing features and general feedback in **Sync**. Be sure to check our [documentation](http://cocoadocs.org/docsets/Sync), [FAQ](https://github.com/SyncDB/Sync/wiki/FAQ) and [past issues](https://github.com/SyncDB/Sync/issues?state=closed) before opening any new issues.

If you are posting about a crash in your application or a feature request, an example of your **JSON** and your **Core Data model** or a **stacktrace** would be really helpful for us to be able to reproduce your issue or understand your request, please consider adding these things before making an issue.
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Licensed under the **MIT** license

> Copyright (c) 2016 Hyper Interaktiv
> Copyright (c) 2016 SyncDB
>
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
Expand Down
50 changes: 25 additions & 25 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
PODS:
- DATAFilter (1.0.0):
- DATAObjectIDs (~> 0.6.0)
- DATAObjectIDs (0.6.0)
- DATASource (6.0.0)
- DATAStack (6.0.0)
- DateParser (0.1.0)
- DATAFilter (1.0.1):
- DATAObjectIDs (~> 0.6.1)
- DATAObjectIDs (0.6.1)
- DATASource (6.0.1)
- DATAStack (6.0.1)
- DateParser (0.1.1)
- JSON (5.0.0)
- NSDictionary-ANDYSafeValue (0.3.1)
- NSEntityDescription-SYNCPrimaryKey (1.2.7):
- NSEntityDescription-SYNCPrimaryKey (1.2.8):
- NSString-HYPNetworking (~> 1.0.6)
- NSManagedObject-HYPPropertyMapper (4.1.2):
- DateParser (~> 0.1.0)
- NSEntityDescription-SYNCPrimaryKey (~> 1.2.7)
- NSManagedObject-HYPPropertyMapper (4.1.3):
- DateParser (~> 0.1.1)
- NSEntityDescription-SYNCPrimaryKey (~> 1.2.8)
- NSString-HYPNetworking (1.0.6)
- Sync (2.1.4):
- DATAFilter (~> 1.0.0)
- DATAStack (~> 6.0.0)
- Sync (2.1.6):
- DATAFilter (~> 1.0.1)
- DATAStack (~> 6.0.1)
- NSDictionary-ANDYSafeValue (~> 0.3.1)
- NSManagedObject-HYPPropertyMapper (~> 4.1.2)
- TestCheck (~> 1.0.0)
- TestCheck (1.0.0)
- NSManagedObject-HYPPropertyMapper (~> 4.1.3)
- TestCheck (~> 1.0.1)
- TestCheck (1.0.1)

DEPENDENCIES:
- DATASource (~> 6)
Expand All @@ -31,18 +31,18 @@ EXTERNAL SOURCES:
:path: "."

SPEC CHECKSUMS:
DATAFilter: 6f6b7de6a004bbb172b78880f72fdc7f618fc4da
DATAObjectIDs: e3d50315134d21009f3b34983bcf44e74d8ab54a
DATASource: fab70e3d22acf03b8eced9a015bdca38b5b08505
DATAStack: 4cdf8e1b50f6d80c7d70f75e7a2c29545a008860
DateParser: 6609ccde5a21650e2f61cea718a2e5c6c34ce4e8
DATAFilter: 34828e513ef704fffd0ffeb99f5f2fb56ce45d94
DATAObjectIDs: add3013859faf600b073051453bb7f902b479334
DATASource: 4038d08f9d7d4fcad81c153f9612ff7eb1789b17
DATAStack: 4138a30db76d535d04f9130847ac59748c6c16aa
DateParser: 17a256f651c5dd754b83aca6ef5827d796a5f292
JSON: 93622160a062588b4cd3497b77ccd777f1fd0587
NSDictionary-ANDYSafeValue: 2d7adf339b6e302d71fec5f1d71ae00aacda993e
NSEntityDescription-SYNCPrimaryKey: c7942c62eb64691576451e1dc180e2067f0a5af8
NSManagedObject-HYPPropertyMapper: 6d26449f1eac74f140906ba2eefebc359da65826
NSEntityDescription-SYNCPrimaryKey: 6e0ca0958f7e05a15e2ed9317e5afeb75af6c782
NSManagedObject-HYPPropertyMapper: b054e2b9c8be5bb24a7f6f1729395cdb5903171c
NSString-HYPNetworking: 97eb879c5c43663dde06f89e01e8e1551a3f5bb7
Sync: 904ee03c4cd9604facae6132dc2b3bdac24f2f69
TestCheck: af3ff0c7c7c22cc4fbcc49a7e10d4187f0cbf1b9
Sync: 90f8d4dd18e29b35f3e49d7f8e08c664e8b0ce89
TestCheck: 93b9acfe503631c3b679ba48bc0ddf9b79f2c2b9

PODFILE CHECKSUM: 2f66666173c7e212ebe798fd96713dc28117babd

Expand Down
45 changes: 19 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
![Hyper Sync™](https://raw.githubusercontent.com/hyperoslo/Sync/master/Images/logo-v2.png)

[![Version](https://img.shields.io/cocoapods/v/Sync.svg?style=flat)](https://cocoapods.org/pods/Sync)
[![License](https://img.shields.io/cocoapods/l/Sync.svg?style=flat)](https://cocoapods.org/pods/Sync)
[![Platform](https://img.shields.io/cocoapods/p/Sync.svg?style=flat)](https://cocoapods.org/pods/Sync)
Expand Down Expand Up @@ -72,7 +70,7 @@ Sync.changes(

### Model

![Model](https://raw.githubusercontent.com/hyperoslo/Sync/master/Images/one-to-many-swift.png)
![Model](https://raw.githubusercontent.com/SyncDB/Sync/master/Images/one-to-many-swift.png)

### JSON

Expand Down Expand Up @@ -129,7 +127,7 @@ Sync.changes(

### Model

![Model](https://raw.githubusercontent.com/hyperoslo/Sync/master/Images/one-to-many-objc.png)
![Model](https://raw.githubusercontent.com/SyncDB/Sync/master/Images/one-to-many-objc.png)

### JSON

Expand Down Expand Up @@ -185,11 +183,11 @@ inEntityNamed:@"User"
## More Examples

<a href="https://github.com/3lvis/SyncAppNetDemo">
<img src="https://raw.githubusercontent.com/hyperoslo/Sync/master/Images/APPNET-v3.png" />
<img src="https://raw.githubusercontent.com/SyncDB/Sync/master/Images/APPNET-v3.png" />
</a>

<a href="https://github.com/3lvis/SyncDesignerNewsDemo">
<img src="https://raw.githubusercontent.com/hyperoslo/Sync/master/Images/DN-v4.png" />
<img src="https://raw.githubusercontent.com/SyncDB/Sync/master/Images/DN-v4.png" />
</a>


Expand Down Expand Up @@ -228,7 +226,7 @@ By default **Sync** uses `id` from the JSON and `id` (or `remoteID`) from Core D

You can mark any attribute as primary key by adding `hyper.isPrimaryKey` and the value `true` (or `YES`). For example, in our [Designer News](https://github.com/3lvis/SyncDesignerNewsDemo) project we have a `Comment` entity that uses `body` as the primary key.

![Custom primary key](https://raw.githubusercontent.com/hyperoslo/Sync/master/Images/custom-primary-key-v3.png)
![Custom primary key](https://raw.githubusercontent.com/SyncDB/Sync/master/Images/custom-primary-key-v3.png)

If you add the flag `hyper.isPrimaryKey` to the attribute `contractID` then:

Expand All @@ -246,12 +244,12 @@ Your attributes should match their JSON counterparts in `camelCase` notation ins

There are some exception to this rule:

* Reserved attributes should be prefixed with the `entityName` (`type` becomes `userType`, `description` becomes `userDescription` and so on). In the JSON they don't need to change, you can keep `type` and `description` for example. A full list of reserved attributes can be found [here](https://github.com/hyperoslo/NSManagedObject-HYPPropertyMapper/blob/master/Source/NSManagedObject%2BHYPPropertyMapper.m#L265)
* Attributes with acronyms will be normalized (`id`, `pdf`, `url`, `png`, `jpg`, `uri`, `json`, `xml`). For example `user_id` will be mapped to `userID` and so on. You can find the entire list of supported acronyms [here](https://github.com/hyperoslo/NSString-HYPNetworking/blob/master/README.md#acronyms).
* Reserved attributes should be prefixed with the `entityName` (`type` becomes `userType`, `description` becomes `userDescription` and so on). In the JSON they don't need to change, you can keep `type` and `description` for example. A full list of reserved attributes can be found [here](https://github.com/SyncDB/NSManagedObject-HYPPropertyMapper/blob/master/Source/NSManagedObject%2BHYPPropertyMapper.m#L265)
* Attributes with acronyms will be normalized (`id`, `pdf`, `url`, `png`, `jpg`, `uri`, `json`, `xml`). For example `user_id` will be mapped to `userID` and so on. You can find the entire list of supported acronyms [here](https://github.com/SyncDB/NSString-HYPNetworking/blob/master/README.md#acronyms).

If you want to map your Core Data attribute with a JSON attribute that has different naming, you can do by adding `hyper.remoteKey` in the user info box with the value you want to map.

![Custom remote key](https://raw.githubusercontent.com/hyperoslo/Sync/master/Images/custom-remote-key-v2.png)
![Custom remote key](https://raw.githubusercontent.com/SyncDB/Sync/master/Images/custom-remote-key-v2.png)

### Attribute Types

Expand Down Expand Up @@ -295,7 +293,7 @@ let expenses = NSKeyedUnarchiver.unarchiveObjectWithData(managedObject.expenses)

#### Dates

We went for supporting [ISO8601](http://en.wikipedia.org/wiki/ISO_8601) and unix timestamp out of the box because those are the most common formats when parsing dates, also we have a [quite performant way to parse this strings](https://github.com/hyperoslo/NSManagedObject-HYPPropertyMapper/blob/master/Source/NSManagedObject%2BHYPPropertyMapper.m#L272-L319) which overcomes the [performance issues of using `NSDateFormatter`](http://blog.soff.es/how-to-drastically-improve-your-app-with-an-afternoon-and-instruments/).
We went for supporting [ISO8601](http://en.wikipedia.org/wiki/ISO_8601) and unix timestamp out of the box because those are the most common formats when parsing dates, also we have a [quite performant way to parse this strings](https://github.com/SyncDB/NSManagedObject-HYPPropertyMapper/blob/master/Source/NSManagedObject%2BHYPPropertyMapper.m#L272-L319) which overcomes the [performance issues of using `NSDateFormatter`](http://blog.soff.es/how-to-drastically-improve-your-app-with-an-afternoon-and-instruments/).

```swift
let values = ["created_at" : "2014-01-01T00:00:00+00:00",
Expand All @@ -317,7 +315,7 @@ let publishedAt = managedObject.value(forKey: "publishedAt")

#### JSON representation from a NSManagedObject

**Sync**'s dependency [**NSManagedObject-HYPPropertyMapper**](https://github.com/hyperoslo/NSManagedObject-HYPPropertyMapper) provides a method to generate a JSON object from any NSManagedObject instance. [More information here.](https://github.com/hyperoslo/NSManagedObject-HYPPropertyMapper#json-representation-from-a-nsmanagedobject)
**Sync**'s dependency [**NSManagedObject-HYPPropertyMapper**](https://github.com/SyncDB/NSManagedObject-HYPPropertyMapper) provides a method to generate a JSON object from any NSManagedObject instance. [More information here.](https://github.com/SyncDB/NSManagedObject-HYPPropertyMapper#json-representation-from-a-nsmanagedobject)

### Relationship mapping

Expand All @@ -327,7 +325,7 @@ let publishedAt = managedObject.value(forKey: "publishedAt")

Lets consider the following Core Data model.

![One-to-many](https://raw.githubusercontent.com/hyperoslo/Sync/master/Images/one-to-many-swift.png)
![One-to-many](https://raw.githubusercontent.com/SyncDB/Sync/master/Images/one-to-many-swift.png)

This model has a one-to-many relationship between `User` and `Note`, so in other words a user has many notes. Here can also find an inverse relationship to user on the Note model. This is required for Sync to have more context on how your models are presented. Finally, in the Core Data model there is a cascade relationship between user and note, so when a user is deleted all the notes linked to that user are also removed (you can specify any delete rule).

Expand Down Expand Up @@ -368,7 +366,7 @@ For example, in the one-to-many example, you have a user, that has many notes. I

A similar procedure is applied to one-to-one relationships. For example lets say you have the following model:

![one-to-one](https://raw.githubusercontent.com/hyperoslo/Sync/master/Images/one-to-one-v2.png)
![one-to-one](https://raw.githubusercontent.com/SyncDB/Sync/master/Images/one-to-one-v2.png)

This model is simple, a user as a company. A compatible JSON would look like this:

Expand Down Expand Up @@ -420,7 +418,7 @@ You are free to use any networking library.

* [**DATAFilter**](https://github.com/3lvis/DATAFilter): Helps you purge deleted objects. Internally we use it to diff inserts, updates and deletes. Also it’s used for uniquing Core Data does this based on objectIDs, DATAFilter uses your remote keys (such as id) for this

* [**NSManagedObject-HYPPropertyMapper**](https://github.com/hyperoslo/NSManagedObject-HYPPropertyMapper): Maps JSON fields with their Core Data counterparts, it does most of it’s job using the paradigm “_convention over configuration_
* [**NSManagedObject-HYPPropertyMapper**](https://github.com/SyncDB/NSManagedObject-HYPPropertyMapper): Maps JSON fields with their Core Data counterparts, it does most of it’s job using the paradigm “_convention over configuration_

## FAQ

Expand Down Expand Up @@ -498,13 +496,13 @@ Logging changes to Core Data is quite simple, just subscribe to changes like thi
}
```

Logging updates is a bit more complicated since this changes don't get propagated to the main context. But if you want an example on how to do this, you can check the AppNet example, [the change notifications demo is in the Networking file](https://github.com/hyperoslo/Sync/blob/master/AppNet/Networking.swift#L27-L57).
Logging updates is a bit more complicated since this changes don't get propagated to the main context. But if you want an example on how to do this, you can check the AppNet example, [the change notifications demo is in the Networking file](https://github.com/SyncDB/Sync/blob/master/AppNet/Networking.swift#L27-L57).

If you're using Swift to be able to use `NSNotificationCenter` your class should be a subclass of `NSObject` or similar.

#### Crash on NSParameterAssert

This means that the local primary key was not found, Sync uses `id` (or `remoteID`) by default, but if you have another local primary key make sure to mark it with `"hyper.isPrimaryKey" : "true"` in your attribute's user info. For more information check the [Primary Key](https://github.com/hyperoslo/Sync#primary-key) section.
This means that the local primary key was not found, Sync uses `id` (or `remoteID`) by default, but if you have another local primary key make sure to mark it with `"hyper.isPrimaryKey" : "true"` in your attribute's user info. For more information check the [Primary Key](https://github.com/SyncDB/Sync#primary-key) section.

```swift
let localKey = entity.sync_localPrimaryKey()
Expand All @@ -516,7 +514,7 @@ assert(remoteKey != nil, "nil value")

#### How to map relationships that don't have IDs?

There are two ways you can sync a JSON object that doesn't have an `id`. You can either set one of it's [attributes as the primary key](https://github.com/hyperoslo/Sync#primary-key), or you can store the JSON object as NSData, I have done this myself in a couple of apps works pretty well. You can find more information on how to store dictionaries using Sync [here](https://github.com/hyperoslo/Sync#arraydictionary).
There are two ways you can sync a JSON object that doesn't have an `id`. You can either set one of it's [attributes as the primary key](https://github.com/SyncDB/Sync#primary-key), or you can store the JSON object as NSData, I have done this myself in a couple of apps works pretty well. You can find more information on how to store dictionaries using Sync [here](https://github.com/SyncDB/Sync#arraydictionary).

#### What if I only want inserts and updates?

Expand All @@ -527,7 +525,7 @@ This is how setting operations should work:
```swift
let firstImport = // First import of users
Sync.changes(firstBatch, inEntityNamed: "User", dataStack: dataStack, operations: [.All]) {
// All users have been imported, they are happy
// All users have been imported, they are happy
}

let secondImport = // Second import of users
Expand All @@ -549,7 +547,7 @@ For a full example on how to do achieve this magic syncing check the [SyncPerfor

#### Which date formats are supported by Sync?

Sync uses an extensive and [blazing fast ISO 8601 parser](https://github.com/3lvis/DateParser). Here are some of the supported formats, if you don't find yours, just open and issue:
Sync uses an extensive and [blazing fast ISO 8601 parser](https://github.com/3lvis/DateParser). Here are some of the supported formats, if you don't find yours, just open and issue:

```
2014-01-02
Expand All @@ -564,11 +562,6 @@ Sync uses an extensive and [blazing fast ISO 8601 parser](https://github.com/3lv
2014-01-02T00:00:00.000000+00:00
```

## Credits

[Hyper](http://hyper.no) made this. We’re a digital communications agency with a passion for good code and delightful user experiences. If you’re using this library we probably want to [hire you](https://github.com/hyperoslo/iOS-playbook/blob/master/HYPER_RECIPES.md) (we consider remote employees too, the only requirement is that you’re awesome).


## License

**Sync** is available under the MIT license. See the [LICENSE](https://github.com/hyperoslo/Sync/blob/master/LICENSE.md) file for more info.
**Sync** is available under the MIT license. See the [LICENSE](https://github.com/SyncDB/Sync/blob/master/LICENSE.md) file for more info.
2 changes: 1 addition & 1 deletion Source/NSManagedObjectContext+Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public extension NSManagedObjectContext {
fatalError("Failed to fetch request for entityName: \(entityName), predicate: \(request.predicate)")
}
} else if let parentRelationshipName = parentRelationshipName {
// More info: https://github.com/hyperoslo/Sync/pull/72
// More info: https://github.com/SyncDB/Sync/pull/72
result = parent?.value(forKey: parentRelationshipName) as? NSManagedObject
}

Expand Down
18 changes: 9 additions & 9 deletions Sync.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Sync"
s.version = "2.1.5"
s.version = "2.1.6"
s.summary = "Modern Swift JSON synchronization to Core Data"
s.description = <<-DESC
**Sync** eases your everyday job of parsing a `JSON` response and getting it into Core Data. It uses a convention-over-configuration paradigm to facilitate your workflow.
Expand All @@ -13,11 +13,11 @@ s.description = <<-DESC
* Smart-updates, only updates your `NSManagedObject`s if the server values are different (useful when using `NSFetchedResultsController` delegates)
* Uniquing, Core Data does this based on `objectID`s, we use your primary key (such as `id`) for this
DESC
s.homepage = "https://github.com/hyperoslo/Sync"
s.homepage = "https://github.com/SyncDB/Sync"
s.license = 'MIT'
s.author = { "Hyper AS" => "[email protected]" }
s.source = { :git => "https://github.com/hyperoslo/Sync.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/hyperoslo'
s.author = { "SyncDB" => "[email protected]" }
s.source = { :git => "https://github.com/SyncDB/Sync.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/Sync_DB'

s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.9'
Expand All @@ -28,9 +28,9 @@ s.source_files = 'Source/**/*'

s.frameworks = 'Foundation', 'CoreData'

s.dependency 'DATAFilter', '~> 1.0.0'
s.dependency 'DATAStack', '~> 6.0.0'
s.dependency 'DATAFilter', '~> 1.0.1'
s.dependency 'DATAStack', '~> 6.0.1'
s.dependency 'NSDictionary-ANDYSafeValue', '~> 0.3.1'
s.dependency 'NSManagedObject-HYPPropertyMapper', '~> 4.1.2'
s.dependency 'TestCheck', '~> 1.0.0'
s.dependency 'NSManagedObject-HYPPropertyMapper', '~> 4.1.3'
s.dependency 'TestCheck', '~> 1.0.1'
end
2 changes: 1 addition & 1 deletion Tests/NSArray+SyncTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import XCTest

class NSArray_SyncTests: XCTestCase {
// Bug 125 => https://github.com/hyperoslo/Sync/issues/125
// Bug 125 => https://github.com/SyncDB/Sync/issues/125

/*func testPreprocessForEntityNamed() {
let formDictionary = Helper.objectsFromJSON("bug-125-light.json") as! [String : NSObject]
Expand Down
Loading

0 comments on commit 669a812

Please sign in to comment.