New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore API for functions #45
Conversation
Current coverage is
|
1/6th complete...
Okay, so there is actually a bit of a problem here. The Swift compiler cannot differentiate between two functions in an extension on the same type which have the same name but different generic where clauses which have inclusive inheritance. So.. for example, given these protocols: protocol FooType {
var baz: Int { get }
}
protocol BarType: FooType {
typealias BatType
} If you define this the following: extension String {
func world<T where T: FooType>() -> T? { return .None }
func world<V where V: BarType, V.BatType == Int>() -> V? { return .None }
} And then try to use it, assuming that you had some let hello = "hello"
let foo: Foo? = hello.world() // Will not compile, ambiguous use of 'world()'
let bar: Bar? = hello.world() // Will not compile, ambiguous user of 'world()' This is the actual error message I have at the moment: Which begs the question, how did this used to work?Well, previously, if you check Not really sure what to do about this.
I'll investigate 3 more. |
Yep, confirmed, I can get it to work for Which is not the end of the world - I can define a |
This means more code re-use and the underlying read/write methods are only used once for each type pattern.
Okay, think that just about does it. |
…ions Restore API for functions
The only problem with adding functions directly to
YapDatabaseReadWriteTransaction
(etc) is that every function needs to be generic. This can be a bit of a problem as this is the generic where clause for value types with value type metadata..which is very verbose and error prone - although less so now that the protocol types are relatively stable.
So, there are a couple of options which might work as alternatives.
Similar to the
Read
andWrite
structures, we could wrapYapDatabaseReadWriteTransaction
,YapDatabaseConnection
inside a generic type, which then has generic methods for read & write. e.g.which is probably the best, although not sure that this is possible.
Add a genericThis will work - but don't think that it'll be possible to have theItemType
to the facade protocolsReadTransactionType
etc and then define the functions in protocol extensions?YapDatabase
types then conform to the protocols. - correct, not a viable solution.I think it's going to have to be fully generic functions. But the can be added to the facade protocols which is better for testing at least. Anyway, so the APIs are as follows...
where
Item
is one of the following type patterns:NSCoding
class with no metadataNSCoding
class withNSCoding
class metadataNSCoding
class withSaveable
value metadataSaveable
value with no metadataSaveable
value withNSCoding
class metadataSaveable
value withSaveable
value metadataNotes:
transaction.readAll() ->
Use thePersistable
extension for this.