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 317f8e1 commit 622effc
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 65 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
32 changes: 16 additions & 16 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
PODS:
- DATAFilter (0.11.2):
- DATAObjectIDs (~> 0.6.0)
- DATAObjectIDs (0.6.0)
- DATAObjectIDs (0.6.1)
- DATASource (5.10.0)
- DATAStack (5.4.2)
- DateParser (0.1.0)
- DateParser (0.1.1)
- JSON (4.0.2)
- NSDictionary-ANDYSafeValue (0.3.1)
- NSEntityDescription-SYNCPrimaryKey (1.2.6):
- NSString-HYPNetworking (~> 1.0.5)
- NSManagedObject-HYPPropertyMapper (4.1.1):
- DateParser (~> 0.1.0)
- NSEntityDescription-SYNCPrimaryKey (~> 1.2.6)
- NSString-HYPNetworking (1.0.5)
- Sync (1.14.2):
- NSEntityDescription-SYNCPrimaryKey (1.2.8):
- NSString-HYPNetworking (~> 1.0.6)
- NSManagedObject-HYPPropertyMapper (4.1.3):
- DateParser (~> 0.1.1)
- NSEntityDescription-SYNCPrimaryKey (~> 1.2.8)
- NSString-HYPNetworking (1.0.6)
- Sync (1.14.4):
- DATAFilter (~> 0.11.2)
- DATAStack (~> 5.4.1)
- NSDictionary-ANDYSafeValue (~> 0.3.1)
Expand All @@ -28,20 +28,20 @@ DEPENDENCIES:

EXTERNAL SOURCES:
Sync:
:path: .
:path: "."

SPEC CHECKSUMS:
DATAFilter: 1d339e27caf0a72d895a1ae664e044fff368a520
DATAObjectIDs: e3d50315134d21009f3b34983bcf44e74d8ab54a
DATAObjectIDs: add3013859faf600b073051453bb7f902b479334
DATASource: 444542bc20734886c3fa46f53ec4b1dbee750950
DATAStack: 931ef9a21c6badd0ff5de494a5d49109ba7e8115
DateParser: 6609ccde5a21650e2f61cea718a2e5c6c34ce4e8
DateParser: 17a256f651c5dd754b83aca6ef5827d796a5f292
JSON: d08f22c3e523be050d5d5f40bca43ec02d95b2cc
NSDictionary-ANDYSafeValue: 2d7adf339b6e302d71fec5f1d71ae00aacda993e
NSEntityDescription-SYNCPrimaryKey: 9449ab486b46ee949421d17d11de8cd7d4c31904
NSManagedObject-HYPPropertyMapper: 765b7b3bcbbfd4c224a2c19620e438b0da09ec64
NSString-HYPNetworking: a42e1fddceabb89735e53cbbb4b5865edd4f2bb6
Sync: 706a7d4b16c1ae6f0450d92109990a382c7d9426
NSEntityDescription-SYNCPrimaryKey: 6e0ca0958f7e05a15e2ed9317e5afeb75af6c782
NSManagedObject-HYPPropertyMapper: b054e2b9c8be5bb24a7f6f1729395cdb5903171c
NSString-HYPNetworking: 97eb879c5c43663dde06f89e01e8e1551a3f5bb7
Sync: a41f5628374be4c3f7b7c7f13cdbc7058dc11bcd
TestCheck: 9a9aad0a356703989f4f2b640b6ed95e53e2214f

PODFILE CHECKSUM: 7a3c7e2d1ff850847d49164a7d6f1dedd5261745
Expand Down
44 changes: 21 additions & 23 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 @@ -221,22 +219,22 @@ Sync requires your entities to have a primary key, this is important for diffing

By default **Sync** uses `id` from the JSON and `id` (or `remoteID`) from Core Data as the primary key.

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/hyperoslo/Sync/tree/master/DesignerNews) project we have a `Comment` entity that uses `body` as the primary key.
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/SyncDB/Sync/tree/master/DesignerNews) 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)

### Attribute Mapping

Your attributes should match their JSON counterparts in `camelCase` notation instead of `snake_case`. For example `first_name` in the JSON maps to `firstName` in Core Data and `address` in the JSON maps to `address` in Core Data.

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 @@ -280,7 +278,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 @@ -302,7 +300,7 @@ let publishedAt = managedObject.valueForKey("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 @@ -312,7 +310,7 @@ let publishedAt = managedObject.valueForKey("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 @@ -353,7 +351,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 @@ -405,7 +403,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 @@ -495,13 +493,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 @@ -513,7 +511,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 @@ -524,7 +522,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 @@ -546,7 +544,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 @@ -563,9 +561,9 @@ Sync uses an extensive and [blazing fast ISO 8601 parser](https://github.com/3lv

## 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).
[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/SyncDB/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?.valueForKey(parentRelationshipName) as? NSManagedObject
}

Expand Down
10 changes: 5 additions & 5 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 = "1.14.3"
s.version = "1.14.4"
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 Down
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 622effc

Please sign in to comment.