 							name: NSManagedObjectContextObjectsDidChangeNotification,
 							object: self_.context)
 					}
-				}
-    }
-
-    context.performBlock {
-      let asyncRequest = NSAsynchronousFetchRequest(fetchRequest: self.fetchRequest, completionBlock: completionBlock)
-
-      do {
-        try self.context.executeRequest(asyncRequest)
-      } catch let error as NSError {
-        fatalError("\(error.description)")
-      }
-    }
-  }
-
-  private func sectionize(fetchedObjects: [E]) {
-    guard let keyPath = sectionNameKeyPath else {
-      sections = [ObjectSetSection(name: ReactiveSetSectionName(nil),
-        array: fetchedObjects)]
-
-      return
-    }
+			}
+		}
+
+		context.performBlock {
+			let asyncRequest = NSAsynchronousFetchRequest(fetchRequest: self.fetchRequest, completionBlock: completionBlock)
+
+			do {
+				try self.context.executeRequest(asyncRequest)
+			} catch let error as NSError {
+				fatalError("\(error.description)")
+			}
+		}
+	}
+
+	private func sectionize(fetchedObjects: [E]) {
+		guard let keyPath = sectionNameKeyPath else {
+			sections = [ObjectSetSection(name: ReactiveSetSectionName(nil),
+				array: fetchedObjects)]
+
+			return
+		}
 
 		if !fetchedObjects.isEmpty {
 			var ranges: [(range: Range<Int>, name: ReactiveSetSectionName)] = []
 
 			// Objects are sorted wrt to sections already.
-      for position in fetchedObjects.startIndex ..< fetchedObjects.endIndex {
-        let sectionName = ReactiveSetSectionName(fetchedObjects[position].valueForKeyPath(keyPath) as? String)
+			for position in fetchedObjects.startIndex ..< fetchedObjects.endIndex {
+				let sectionName: ReactiveSetSectionName
+
+				switch fetchedObjects[position].valueForKeyPath(keyPath) {
+				case let name as String:
+					sectionName = ReactiveSetSectionName(name)
+				case let name as NSNumber:
+					sectionName = ReactiveSetSectionName(name.stringValue)
+				default:
+					sectionName = ReactiveSetSectionName(nil)
+				}
 
 				if ranges.isEmpty || ranges.last?.name != sectionName {
 					ranges.append((range: position ..< position + 1, name: sectionName))
 				} else {
 					ranges[ranges.endIndex - 1].range.endIndex += 1
 				}
-      }
+			}
 
 			sections.reserveCapacity(ranges.count)
 

		let indiceOfDeletedSections = NSMutableIndexSet()
		let indiceOfInsertedSections = NSMutableIndexSet()

    indexPathsOfInsertedRows.reserveCapacity(externalChanges.insertedObjectsCount)
    indexPathsOfDeletedRows.reserveCapacity(externalChanges.deletedObjectsCount)
    indexPathsOfUpdatedRows.reserveCapacity(externalChanges.updatedObjectsCount)
    indexPathsOfMovedRows.reserveCapacity(originsOfMoved.capacity)

    for (sectionName, objects) in externalChanges.deletedObjects {
			guard let sectionIndex = oldSections.indexFor(sectionName) else {
				assertionFailure("Section `\(sectionName)` should be in the result set, but it cannot be found.")
				continue
			}

      for object in objects {
				guard let rowIndex = oldSections[sectionIndex].indexOf(object) else {
					assertionFailure("Object `\(object)` should be in the section `\(sectionName)`, but it cannot be found.")
					continue
				}

        let indexPath = NSIndexPath(forRow: rowIndex, inSection: sectionIndex)
        indexPathsOfDeletedRows.append(indexPath)
      }
    }

    for (oldSectionName, objects) in externalChanges.movedObjects {
			guard let oldSectionIndex = oldSections.indexFor(oldSectionName) else {
				assertionFailure("Section `\(oldSectionName)` should be in the result set, but cannot be found.")
				continue
			}

      for object in objects {
				guard let rowIndex = oldSections[oldSectionIndex].indexOf(object) else {
					assertionFailure("Object `\(object)` should be in the section `\(oldSectionName)`, but it cannot be found.")
					continue
				}

				let indexPath = NSIndexPath(forRow: rowIndex, inSection: oldSectionIndex)
        originsOfMoved.append(indexPath)
      }
    }
    
    for indexPath in originsOfMoved {
      let object = oldSections[indexPath.section][indexPath.row]
      let sectionName = sectionNameFor(object)
      inboundObjects.insert(object, inSetForKey: sectionName)
    }

    var pendingDelete = ContiguousArray<NSIndexPath>()
		pendingDelete.appendContentsOf(originsOfMoved)
		pendingDelete.appendContentsOf(indexPathsOfDeletedRows)
    pendingDelete.sortInPlace { $0.row > $1.row }

    for indexPath in pendingDelete {
      updatedSections[indexPath.section].removeAtIndex(indexPath.row)
    }

    for sectionIndex in updatedSections.indices {
      if updatedSections[sectionIndex].count == 0 {
        indiceOfDeletedSections.addIndex(sectionIndex)
      }
    }

    for sectionIndex in indiceOfDeletedSections.reverse() {
      updatedSections.removeAtIndex(sectionIndex)
    }

    for (sectionName, objects) in externalChanges.insertedObjects {
      if let sectionIndex = updatedSections.indexFor(sectionName) {
        updatedSections[sectionIndex].appendContentsOf(objects)
      } else {
				let index = updatedSections.insertSection(sectionName,
					ordering: sectionNameOrdering,
					section: ObjectSetSection(name: sectionName,
						array: Array(objects)))

        indiceOfInsertedSections.addIndex(index)
      }
    }

    for (sectionName, objects) in inboundObjects {
      if let sectionIndex = updatedSections.indexFor(sectionName) {
        updatedSections[sectionIndex].appendContentsOf(objects)
      } else {
        let index = updatedSections.insertSection(sectionName,
					ordering: sectionNameOrdering,
					section: ObjectSetSection(name: sectionName,
						array: Array(objects)))

        indiceOfInsertedSections.addIndex(index)
      }
    }

    for sectionIndex in updatedSections.indices {
			let sectionName = updatedSections[sectionIndex].name
			let oldSectionIndex = oldSections.indexFor(sectionName)

      updatedSections[sectionIndex]._sortInPlace(objectSortDescriptors)

      for (objectIndex, object) in updatedSections[sectionIndex].enumerate() {
        if let oldSectionIndex = oldSectionIndex {
          if objectIndex < oldSections[oldSectionIndex].count && object == oldSections[oldSectionIndex][objectIndex] {
            if let isUpdated = externalChanges.updatedObjects[sectionName]?.contains(object) where isUpdated {
              let indexPath = NSIndexPath(forRow: objectIndex, inSection: sectionIndex)
              indexPathsOfUpdatedRows.append(indexPath)
            }
            continue
          }
        }

        if let isInserted = externalChanges.insertedObjects[sectionName]?.contains(object) where isInserted {
          indexPathsOfInsertedRows.append(NSIndexPath(forRow: objectIndex, inSection: sectionIndex))
          continue
        }

        if let inboundIndex = inboundObjects[sectionName]?.indexOf(object) {
          if indiceOfDeletedSections.contains(originsOfMoved[inboundIndex].section) {
            let indexPath = NSIndexPath(forRow: objectIndex, inSection: sectionIndex)
            indexPathsOfInsertedRows.append(indexPath)
          } else if indiceOfInsertedSections.contains(sectionIndex) {
            let indexPath = NSIndexPath(forRow: objectIndex, inSection: sectionIndex)
            indexPathsOfDeletedRows.append(originsOfMoved[inboundIndex])
            indexPathsOfInsertedRows.append(indexPath)
          } else {
            let from = originsOfMoved[inboundIndex]
            let to = NSIndexPath(forRow: objectIndex, inSection: sectionIndex)
            indexPathsOfMovedRows.append((from, to))
          }
          continue
        }

        if let oldSectionIndex = oldSectionIndex, oldIndex = oldSections[oldSectionIndex].indexOf(object) {
          let from = NSIndexPath(forRow: oldIndex, inSection: oldSectionIndex)
          let to = NSIndexPath(forRow: objectIndex, inSection: sectionIndex)
          indexPathsOfMovedRows.append((from, to))
          continue
        }
      }
    }
    
    sections = updatedSections

		let resultSetChanges = ReactiveSetChanges(indexPathsOfDeletedRows: indexPathsOfDeletedRows,
			indexPathsOfInsertedRows: indexPathsOfInsertedRows,
			indexPathsOfMovedRows: indexPathsOfMovedRows,
			indexPathsOfUpdatedRows: indexPathsOfUpdatedRows,
			indiceOfInsertedSections: indiceOfInsertedSections,
			indiceOfDeletedSections: indiceOfDeletedSections)

    eventObserver?.sendNext(.Updated(resultSetChanges))
  }
  
  deinit {
    eventObserver?.sendCompleted()
  }
}

extension ObjectSet: ReactiveSet {


								continue
							}
						}
					} else {
						sectionName = ReactiveSetSectionName(nil)
					}

					notification.updatedObjects.insert(object, inSetForKey: sectionName)
					notification.updatedObjectsCount = notification.updatedObjectsCount + 1
				}
			}
		}

		return notification
	}

	private func apply(externalChanges: ExternalChanges<E>) {
		let oldSections = sections
		var updatedSections = sections

		var inboundObjects = [ReactiveSetSectionName: ContiguousArray<E>](minimumCapacity: externalChanges.movedObjects.count)
		var originsOfMoved = ContiguousArray<NSIndexPath>()
		originsOfMoved.reserveCapacity(externalChanges.movedObjectsCount)

		var indexPathsOfInsertedRows = [NSIndexPath]()
		var indexPathsOfDeletedRows = [NSIndexPath]()
