 import ReactiveCocoa
 
 public class Object: NSManagedObject {
-  final private var _isFaulted = MutableProperty<Bool>(true)
-  final private(set) public lazy var isFaulted: AnyProperty<Bool> = AnyProperty(self._isFaulted)
+	final private var _isFaulted = MutableProperty<Bool>(true)
+	final private(set) public lazy var isFaulted: AnyProperty<Bool> = AnyProperty(self._isFaulted)
 
 	required override public init(entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?) {
 		super.init(entity: entity, insertIntoManagedObjectContext: context)
 	}
 
-  public override func awakeFromInsert() {
-    super.awakeFromInsert()
-    _isFaulted.value = false
-  }
-  
-  public override func awakeFromFetch() {
-    super.awakeFromFetch()
-    _isFaulted.value = false
-  }
+	public override func awakeFromInsert() {
+		super.awakeFromInsert()
+		_isFaulted.value = false
+	}
 
-  public override func prepareForDeletion() {
-    super.prepareForDeletion()
-    _isFaulted.value = true
-  }
-  
-  public override func willTurnIntoFault() {
-    super.willTurnIntoFault()
-    _isFaulted.value = true
-  }
+	public override func awakeFromFetch() {
+		super.awakeFromFetch()
+		_isFaulted.value = false
+	}
+
+	public override func prepareForDeletion() {
+		super.prepareForDeletion()
+		_isFaulted.value = true
+	}
+
+	public override func willTurnIntoFault() {
+		super.willTurnIntoFault()
+		_isFaulted.value = true
+	}
 
 	/// Important: The returned producer will fire a fault when started.
 	final public func producer<Value: CocoaBridgeable where Value.Inner: CocoaBridgeable>(forKeyPath keyPath: String, type: Value.Type? = nil) -> SignalProducer<Value, NoError> {

				.startWithNext { isFaulted in
					if !isFaulted {
						kvoController = AttributeKVOController(object: strongSelf,
																									 keyPath: keyPath,
																									 newValueObserver: { observer.sendNext(Value(cocoaValue: $0)) })
					} else {
						kvoController = nil
					}
				}

			strongSelf.didAccessValueForKey(nil)
		}

			}
		}
	}

	final public func save() throws {
		try objectContext.save()
	}

	final public static var entityName: String {
		return String(Self)
	}


	final public static func with(context: ObjectContext,
	                              @noescape action: (inout using: FetchRequestBuilder) throws -> Void) rethrows -> ResultProducer<Self> {
		var builder = FetchRequestBuilder(entity: entityName, in: context)
		try action(using: &builder)
		return ResultProducer(builder: builder)
