Comments (14)
@ashleydw @Willian-Zhang new macro Inherits
has been added (only in main
branch, not released yet) to workaround the issue until this is fixed from compiler.
from metacodable.
Here's a repo: https://github.com/ashleydw/metacodable-min-ex/blob/main/test/Item.swift
If you build you should get the same error on Item.swift. Commenting out @Codable
and CodedAt
should build successfully and run.
from metacodable.
Thanks @ashleydw for providing sample, I can reproduce your issue. The issue doesn't seem to be combining @Codable
with SwiftData class, in fact the project builds successfully if you comment out following lines:
https://github.com/ashleydw/metacodable-min-ex/blob/c0bd383995ca3c12938f704b79429e2c9c7b0c9b/test/ContentView.swift#L6
https://github.com/ashleydw/metacodable-min-ex/blob/c0bd383995ca3c12938f704b79429e2c9c7b0c9b/test/ContentView.swift#L11-L18
https://github.com/ashleydw/metacodable-min-ex/blob/c0bd383995ca3c12938f704b79429e2c9c7b0c9b/test/ContentView.swift#L50
https://github.com/ashleydw/metacodable-min-ex/blob/c0bd383995ca3c12938f704b79429e2c9c7b0c9b/test/ContentView.swift#L58
Seems like with these line present Swift is not providing protocol conformance data to @Codable
. It would be better if you create a discussion on Swift forum or Apple developer forum as the issue doesn't seem to be MetaCodable
related.
from metacodable.
@soumyamahunt great insight!
@soumyamahunt @ashleydw Are you available to fire a bug report or discussion as you said to apple by any chance?
I don't think I'm qualified enough for this as I'm new to SwiftLang let alone any insight on how swift macro works.
If not, do you think there is way to go around with this problem? I am very interested in this cross usage on SwiftData+MetaCodable, as it would vastly simplify my code in a project that I started recently. (Actually I'm current on a track giving up on #Preview
capability just to have this working)
from metacodable.
having Inherits tested, I can confirm this solved my problem perfectly.
from metacodable.
@rursache you have to remove the manual Codable
conformance you are adding, due to this addition compiler is also generating Codable
implementation which is conflicting with this library's generated implementation.
from metacodable.
If a SwiftData model annotation is added to a class, the build will fail with "Method does not override any method from its superclass".
It can be reproduced using a clean SwiftData project, adding the SPM package from 1.2.1, and the following class:
import Foundation import SwiftData import MetaCodable import HelperCoders protocol MyProtocol { } @Codable @Model final class Item : MyProtocol { @CodedAt("timestamp") var timestamp: Date? = nil init() { } }
Are you sure you are able to reproduce this with this code snippet, for me this code snippet doesn't produce error. Can you provide a sample project for this?
I have however managed to produce one expansion with the error:
Can you provide sample project for this, I can think of one scenario where this error would come:
Note
If you are manually conforming to Codable
protocol in the class, please remove the conformance as @Codable
macro itself generates the conformance.
Anyway I can't do much here with the screenshots, please provide a minimal reproducible sample.
from metacodable.
Same issue here,
problem magically disappear when #Preview
section commented out of some random View (no @ State
, no @Query
no anything), other #Preview
that contains a @Query
not affected by this
from metacodable.
And it happens to me when I move @Bindable var someEnvObject = someEnvObject
in scope of a body of a View that takes and EnvroementObject (check below for doc), to 1 ZStack
level inside...
// @Bindable var someEnvObject = someEnvObject <- from here
ZStack {
@Bindable var someEnvObject = someEnvObject <- to here
// some other code using `someEnvObject`
}
![image](https://private-user-images.githubusercontent.com/5165840/298662074-ef34d92e-32e8-4734-8c4d-f451c2a78313.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTcyMDY1MDQsIm5iZiI6MTcxNzIwNjIwNCwicGF0aCI6Ii81MTY1ODQwLzI5ODY2MjA3NC1lZjM0ZDkyZS0zMmU4LTQ3MzQtOGM0ZC1mNDUxYzJhNzgzMTMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYwMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MDFUMDE0MzI0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OTgzMzU1OGMzMmVlNzhjYmQ1MzY4ZGE5MDRkNTk1ODY3YTY5ZjVjYzA3ZWU3Njg3YWRjNGIzMWQ2YjRmMTQ0MiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.UwUKJJs5kOlzDrBgNQUK-PAljB1YvaaMmSB8uLy9lD4)
(Apple doc)[https://developer.apple.com/documentation/swiftui/bindable]
from metacodable.
@ashleydw @Willian-Zhang has any of you created discussion on Swift forum or Apple developer forum?
I am afraid this issue is not related to MetaCodanle
, taking the discussion to Swift team/Apple is the only solution to this.
from metacodable.
@ashleydw @Willian-Zhang has any of you created discussion on Swift forum or Apple developer forum?
I am afraid this issue is not related to
MetaCodanle
, taking the discussion to Swift team/Apple is the only solution to this.
I haven't, I wasn't able to identify where the problem lies to.
The only thing I can be sure about is that it happens with this use case and reporting this exact error from @Codable
generated code.
from metacodable.
@ashleydw @Willian-Zhang has any of you created discussion on Swift forum or Apple developer forum?
I am afraid this issue is not related toMetaCodanle
, taking the discussion to Swift team/Apple is the only solution to this.I haven't, I wasn't able to identify where the problem lies to. The only thing I can be sure about is that it happens with this use case and reporting this exact error from
@Codable
generated code.
Simple overview of the class implementation generation by @Codable
:
-> Does Class conform to `Decodable`/`Encodable`? (passed from Swift compiler to `MetaCodable`)
-> Yes
-> Are `Decodable`/`Encodable` conformance implemented i.e. `init(from:)`/`encode(to:)` method implementation exist?
-> Yes
-> Skip generating implementation
-> No
-> Assume that super class conforms to `Decodable`/`Encodable` and provide generated implementation.
-> No
-> No super class conforms to `Decodable`/`Encodable` and provide generated implementation.
The strange thing here is without those lines the Swift compiler invokes the following flow:
-> Does Class conform to `Decodable`/`Encodable`? (passed from Swift compiler to `MetaCodable`)
-> No
-> No super class conforms to `Decodable`/`Encodable` and provide generated implementation.
and with those lines present the Swift compiler invokes the following flow:
-> Does Class conform to `Decodable`/`Encodable`? (passed from Swift compiler to `MetaCodable`)
-> Yes
-> Are `Decodable`/`Encodable` conformance implemented i.e. `init(from:)`/`encode(to:)` method implementation exist?
-> No
-> Assume that super class conforms to `Decodable`/`Encodable` and provide generated implementation.
which is a strange behaviour from compiler, as of why compiler provides wrong data in some cases, only Swift compiler team can answer.
from metacodable.
not sure what i'm doing wrong. using the main
branch and this code:
@Codable
@Model
@Inherits(decodable: false, encodable: false)
final class TestModel: Codable, Identifiable {
var id: Int = 0
var url: String = ""
var name: String = ""
init(id: Int, url: String, name: String) {
self.id = id
self.url = url
self.name = name
}
}
Fails with
Redundant conformance of 'EpisodeModel' to protocol 'Decodable'
Redundant conformance of 'EpisodeModel' to protocol 'Encodable'
EDIT: solved by removing the Codable, Identifiable
conformance, my bad!
from metacodable.
@soumyamahunt I can confirm it works in my project, thanks!
from metacodable.
Related Issues (20)
- Note of appreciation :) + Some questions HOT 6
- Assistance with rojopolis/spellcheck-github-actions ? HOT 4
- Derive access level of generate CodingKeys from @Codable model HOT 5
- Provide default value of nil for empty strings HOT 5
- Does IgnoreCoding support properties with didSet? HOT 1
- Distribute a prebuilt binary HOT 3
- @CodedBy and ValueCoder not in scope HOT 1
- Support for different coding keys for encoding / decoding the same property
- Cocoapods installation does not work HOT 8
- `@CodedAs` fails with same keys in different casing
- A way to log when a property defaults on the default value HOT 3
- [Bug] `CodedAs` causes crash in enum when encoding. HOT 5
- `MetaProtocolCodable` cannot handle Optional value correctly HOT 2
- [Feature Request] Encodable Default Value Handling HOT 2
- Xcode build archive fails HOT 2
- [Feature Request] No HelperCoder generated when check compilation condition HOT 3
- No value associated with key CodingKeys HOT 3
- Custom parsing logic inside decoding method HOT 1
- [Help wanted] How can it test the macro test? HOT 4
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 metacodable.