Comments (4)
Awesome! Thanks man!
from defaultskit.
Hi @kmcgill88,
The generic Type of Key ValueType
, or T
in your example, is already a Codable:
public final class Key<ValueType: Codable> { }
So it's redundant to specify it. Try writing this:
func save<T>(_ object: T, key: Key<T>) { }
And it should automatically infer the save
method signature as:
func save<T>(_ object: T, key: Key<T>) where T : Decodable, T : Encodable
from defaultskit.
Ah, that did the trick! Thank you! I don't quite understand how it is inferred though.
I did see ValueType
is scoped to Codable
in your code, so in my code, key: Key<T>
, is it accurate to say T
is inferred to be Codable
because thats what your Key
type requires?
Further, since I'm reusing T
, _ object: T
, it also has the inference because T
is in the same argument scope
? If I changed to _ object: U
then I would have to scope U
to be Codable
.
Am I following correctly?
from defaultskit.
Yes, all of the above are correct.
from defaultskit.
Related Issues (20)
- memory leak HOT 1
- only support swift4? HOT 1
- Support Implicit Member Expression HOT 1
- How to read it out from different View Controller? HOT 4
- Missing DefaultsKey HOT 6
- why type of Key class must be generic? HOT 2
- blob HOT 1
- DefaultsKit does not handle arguments passed on launch
- Swift.EncodingError.Context(codingPath: [], debugDescription: "Top-level Data encoded as string JSON fragment.", underlyingError: nil) HOT 1
- Swift5.1 support HOT 1
- The array object
- Test has function on simulator iOS10.3.1 always true
- Xcode 12.0.1 & SPM HOT 3
- how to add default value to Keys?
- how to initialise default with suitname ?
- Build failed with Xcode14.3
- Storing array of complex objects
- how to support array or dict? HOT 2
- How to extend Key class Key with keys? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from defaultskit.