Last active
February 20, 2019 07:34
-
-
Save BasThomas/ca35c663ff11cc9121be845fc4352760 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Beware: this is "pseudocode", which is not guaranteed to compile. ;-) | |
import CoreData | |
protocol CoreDataProtocol { | |
var managedObjectContext: NSManagedObjectContext? { get } | |
} | |
class Card: NSManagedObject, CoreDataProtocol { | |
// conforms by default | |
} | |
struct CardMock: CoreDataProtocol { | |
let managedObjectContext: NSManagedObjectContext? | |
var card: CardThing? { | |
if let _ = _managedObjectContext { | |
// we have one, return a card | |
return CardThing() | |
} else { | |
// it is nil, return nil | |
return nil | |
} | |
} | |
init(managedObjectContext context: NSManagedObjectContext?) { | |
managedObjectContext = context | |
} | |
} | |
XCTAssertNil(CardMock(managedObjectContext: nil).card) | |
XCTAssertNotNil(CardMock(managedObjectContext: NSManagedObjectContext()).card) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment