I have been trying to compile and run an example App embedded in a Swift package, but failed. I have extracted the app and tried building it but it can't find the package and nothing I do fixes it. Can someone please let me into the secret.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Coredata used to save attributed strings, but now requires a secure coding transformer. I have tried the code below, but it fails claiming
This decoder will only decode classes that adopt NSSecureCoding. Class '__SwiftValue' does not adopt it
The transformer has been registered and the attributes given the name 'AttributedStringToDataTransformer'
Any suggestions as to what is wrong?
Here's the code:
class AttributedStringToDataTransformer: ValueTransformer {
override func transformedValue(_ value: Any?) - Any? {
let boxedData = try! NSKeyedArchiver.archivedData(withRootObject: value!, requiringSecureCoding: true)
return boxedData
}
override func reverseTransformedValue(_ value: Any?) - Any? {
let typedBlob = value as! Data
let data = try! NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSAttributedString.self], from: typedBlob)
return (data as! NSAttributedString)
}
}
extension AttributedStringToDataTransformer {
/// The name of the transformer. This is the name used to register the transformer using `ValueTransformer.setValueTrandformer(_"forName:)`.
static let name = NSValueTransformerName(rawValue: String(describing: AttributedStringToDataTransformer.self))
/// Registers the value transformer with `ValueTransformer`.
public static func register() { ValueTransformer.setValueTransformer(AttributedStringToDataTransformer(), forName: name)
}
}
TextKit 2 looks great. The video demonstrates the sample app on both MacOS and iPad. However the downloaded code only works on MacOS and the documentation says the NSTextViewportLayoutController is only available on MacOS, so when can we expect the IOS versions. And what about integration with SwiftUI?
Is there a way of adding a border to a SwiftUI Menu. By this I mean the menu that appears when its button is tapped, not the button itself. I've tried using .menuStyle, but this only seems to affect the button.
I have an NSAttributedString attribute in an entity marked as Transformable with the transformer set to NSSecureUnarchiveFromDataTransformerName.
I have a Transformer defined as:
class AttributedStringTransformer: NSSecureUnarchiveFromDataTransformer {
override class func allowsReverseTransformation() -> Bool {
return true
}
override class func transformedValueClass() -> AnyClass {
return NSAttributedString.self
}
override class var allowedTopLevelClasses: [AnyClass] {
return [NSAttributedString.self]
}
override func transformedValue(_ value: Any?) -> Any? {
guard let data = value as? Data else {
fatalError("Wrong data type: value must be a Data object; received \(type(of: value))")
}
return super.transformedValue(data)
}
override func reverseTransformedValue(_ value: Any?) -> Any? {
guard let string = value as? NSAttributedString else {
fatalError("Wrong data type: value must be a Reminder object; received \(type(of: value))")
}
return super.reverseTransformedValue(string)
}
}
extension AttributedStringTransformer {
/// The name of the transformer. This is the name used to register the transformer using `ValueTransformer.setValueTrandformer(_"forName:)`.
static let name = NSValueTransformerName(rawValue: String(describing: AttributedStringTransformer.self))
/// Registers the value transformer with `ValueTransformer`.
public static func register() {
let transformer = AttributedStringTransformer()
ValueTransformer.setValueTransformer(transformer, forName: name)
}
}
The transformer is registered on launch.
When I launch the app with the string initialised to an empty attributed string the app fails right away with:
CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x6000005679c0> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
2021-08-12 08:53:30.390456+0100 Easiwriter[5985:108985] [error] error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
CoreData: error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
2021-08-12 08:53:30.391637+0100 Easiwriter[5985:108985] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x600000550a80> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x600000550a80> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
2021-08-12 08:53:30.458505+0100 Easiwriter[5985:108985] [error] error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
CoreData: error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
2021-08-12 08:53:30.459614+0100 Easiwriter[5985:108985] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x600000550a80> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x600000550a80> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
2021-08-12 08:53:30.459835+0100 Easiwriter[5985:108985] [error] error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
CoreData: error: -executeRequest: encountered exception = <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo = (null)
2021-08-12 08:53:30.471535+0100 Easiwriter[5985:108985] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x60000056d8c0> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
CoreData: error: SQLCore dispatchRequest: exception handling request: <NSSQLSaveChangesRequestContext: 0x60000056d8c0> , <shared NSSecureUnarchiveFromData transformer> threw while encoding a value. with userInfo of (null)
I have put break points on the transformer, but it never hits them.
The behaviour of the app gives me the feeling that this is a bug in CoreData, but I can't pin it down.
Can someone please suggest what might be wrong. I am using Xcode 13.0 beta 5 (it failed on beta 4 as well).
I have been trying to get an app accepted but the review team has rejected it 4 times now on the grounds that I have selected 'made for kids'. I have never dome this if they mean the checkbox in the age rating thread. I have even sent them a screen shot. They never reply to my requests for an explanation. The stupid thing is that this app in its Mac Catalyst form was accepted a week ago and is on sale. I have lodged an appeal. Has anyone else had to put up with this?
For the last few months the battery on my MacBook has drained within 24 hours in sleep mode. I have Ventura 13 installed and suspect it's somehow the culprit. There are no apps left running. Any suggestions?
Something weird has happened to my machine. It says it is running Ventura. But I had upgraded to Monterey some time ago. If I go to Software update there is no Monterey option, just a later version of Ventura.
A Monterey disk icon appears on my desktop after startup (separate from Macintosh HD). If I open this it's empty. If I eject it it it says Preboot wasn't ejected, if I force that then it says Update wasn't ejected, then finally forcing that says VM wasn't ejected. That gets rid of it until the next restart.
Has anyone any idea what is going on.
I just installed Xcode beta 6 and tried compiling the SwiftData sample app. It fails with a couple of dozen compile errors. Clearly this must have worked for WWDC23 so what's gone wrong?
The following says type 'Card' does not conform to protocol 'PersistentModel'
@Model
final class Card: PersistentModel {
This seems pretty basic.
Any suggestions
Connect says I have to update agreements, tax and banking, but when I try and load the page the browser hangs and doesn't load the page. I am using Safari and Sonoma. This looks like a bug.
I have a SwiftUI view that I'm trying to dismiss with a button.
Here's the dismiss code:
struct MyBackButton: View {
var backButton: Bool
var dismiss: DismissAction
var body: some View {
Button(
action: dismiss.callAsFunction
) {
HStack {
if backButton {
Image(systemName: "chevron.left")
.imageScale(.large)
Text("Write!")
} else {
Text(" ")
}
}.foregroundColor(Color("AccentColor"))
}
}
}
The containing view contains the environment declaration and the button code:
struct ProjectView: View {
@Environment(\.dismiss) private var dismiss
here's the body of the view containing the following modifier that creates the button
.configureView("Write!", publisher: publisher, dismiss: dismiss)`
When the button is pressed the dismiss action is invoked but nothing happens.
I've tried many variants of this code without success. Any help welcomed.
I am using Xcode 15.3 beta.
I have downloaded the latest beta and tried testing Mac OS Catalyst. It consistently fails with a signing error. I tried using an iPhone 17.2 sim but that failed to install throwing up 'Unable to boot device because it cannot be located on disk', so I reinstalled the sim but got the same error. I then tried 17.4 which simply hangs on the install.
So friends, yesterday I was progressing using beta 2, but today I have hit a show stopper. Am I the only one?
If I annotate a class with @Observable I get this error in @Query:
Expansion of macro 'Query()' produced an unexpected 'init' accessor
If I remove @Observable the error goes away.
Elsewhere I have .environment referencing the class. With @Observable this complains that the class needs to be @Observable.
I am mystified. Does anyone have a suggestion?
I have spent hours trying to get @Query macros to compile. Mostly they throw up meaningless errors for example the following produces 3 compiler errors:
@Query var stylesheets: [StyleSheet]
Here's the expansion.
The compiler complains that 'private' can't be used here, and it can't find _stylesheets. I searched everywhere to find a resolution then I came across the Query struct. I used it as follows to replace the @Query:
let query = Query(FetchDescriptor<StyleSheet>(), animation: .smooth)
let styleSheets = query.wrappedValue
This also solves another issue that was bugging me - how to get the context when the environment variable is often rejected. All I need to do now is write:
let context = query.modelContext
None of the WWDC23 SwiftData videos mentions the use of the struct, which is a shame. It feels much like the CoreData approach to fetching data.
I hope this helps some of you.
I am converting a large core data app to SwiftData and have hit a problem I can't fix, namely code generated by a Model crashing.
Here is the model showing the failing expansion.
Here is the model containing the inverse for the failing attribute:
/Users/writingshedprod/Desktop/Screenshot 2024-05-08 at 20.21.51.png
And here is the mass of core data output generated when the app launches. If anyone can make sense of this I'd be grateful. This is where the problem might lie.
Debugger.txt