I was adding WidgetExtension target for my old project.
The widget target is running fine in iOS 17, In my case, widget need to support iOS 14 and above, so I updated my widget code to old style, To removing WidgetConfigurationIntent and AppIntentTimelineProvider.
import WidgetKit
import SwiftUI
struct Provider: TimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
SimpleEntry()
}
func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> Void) {
completion(SimpleEntry())
}
func getTimeline(in context: Context, completion: @escaping (Timeline<SimpleEntry>) -> Void) {
completion(Timeline(entries: [SimpleEntry()], policy: .never))
}
typealias Entry = SimpleEntry
}
struct SimpleEntry: TimelineEntry {
let date: Date = Date()
}
struct NCWidgetEntryView : View {
var entry: Provider.Entry
var body: some View {
VStack {
Text("Time:")
Text(entry.date, style: .time)
}
}
}
struct NCWidget: Widget {
let kind: String = "NCWidget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
NCWidgetEntryView(entry: entry)
}
.configurationDisplayName("DisplayName")
.description("description")
}
}
In my case, the code was working fine in iOS 17 simulator, But if I try to run in iOS 15, it returns the below error
code-SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=8 "Failed to show Widget 'com.name-pprd.NCWidgetExtension' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=5 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedDescription=The request to open "com.apple.springboard" failed., NSLocalizedFailureReason=Unexpected error type., NSUnderlyingError=0x600003570b40 {Error Domain=BSServiceConnectionErrorDomain Code=3 "XPC error received on message reply handler" UserInfo={BSErrorCodeDescription=OperationFailed, NSLocalizedFailureReason=XPC error received on message reply handler}}, BSErrorCodeDescription=InvalidResponse}." UserInfo={NSLocalizedDescription=Failed to show Widget 'com.name-pprd.NCWidgetExtension' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=5 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedDescription=The request to open "com.apple.springboard" failed., NSLocalizedFailureReason=Unexpected error type., NSUnderlyingError=0x600003570b40 {Error Domain=BSServiceConnectionErrorDomain Code=3 "XPC error received on message reply handler" UserInfo={BSErrorCodeDescription=OperationFailed, NSLocalizedFailureReason=XPC error received on message reply handler}}, BSErrorCodeDescription=InvalidResponse}., NSUnderlyingError=0x600003570bd0 {Error Domain=FBSOpenApplicationServiceErrorDomain Code=5 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedDescription=The request to open "com.apple.springboard" failed., NSLocalizedFailureReason=Unexpected error type., NSUnderlyingError=0x600003570b40 {Error Domain=BSServiceConnectionErrorDomain Code=3 "XPC error received on message reply handler" UserInfo={BSErrorCodeDescription=OperationFailed, NSLocalizedFailureReason=XPC error received on message reply handler}}, BSErrorCodeDescription=InvalidResponse}}}
Domain: DTXMessage
Code: 1
User Info: {
DVTErrorCreationDateKey = "2024-07-20 17:30:58 +0000";
}
--
System Information
macOS Version 14.5 (Build 23F79)
Xcode 15.0.1 (22266) (Build 15A507)
Timestamp: 2024-07-20T23:00:58+05:30
In widget target Minimum target is 14.0
In App target Minimum target is 13.0
Post
Replies
Boosts
Views
Activity
For some time now Xcode has been downloading crash reports from users of my app about crashes related to arrays. One of them looks like this:
...
Code Type: ARM-64
Parent Process: launchd [1]
User ID: 501
Date/Time: 2024-07-18 14:59:40.4375 +0800
OS Version: macOS 15.0 (24A5289h)
...
Crashed Thread: 0
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001045048b8
Termination Reason: Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process: exc handler [1771]
Thread 0 Crashed:
0 MyApp 0x00000001045048b8 specialized Collection.map<A>(_:) + 596
1 MyApp 0x00000001045011e4 MyViewController.validateToolbarButtons() + 648 (MyViewController.swift:742)
...
The relevant code looks like this:
class MyViewController {
func validateToolbarButtons() {
let indexes = tableView.clickedRow == -1 || tableView.selectedRowIndexes.contains(tableView.clickedRow) ? tableView.selectedRowIndexes : IndexSet(integer: tableView.clickedRow)
let items = indexes.map({ myArray[$0] })
...
}
}
The second crash looks like this:
...
Code Type: X86-64 (Native)
Parent Process: launchd [1]
User ID: 502
Date/Time: 2024-07-15 15:53:35.2229 -0400
OS Version: macOS 15.0 (24A5289h)
...
Crashed Thread: 0
Exception Type: EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000
Termination Reason: Namespace SIGNAL, Code 4 Illegal instruction: 4
Terminating Process: exc handler [13244]
Thread 0 Crashed:
0 libswiftCore.dylib 0x00007ff812904fc0 _assertionFailure(_:_:flags:) + 288
1 MyApp 0x0000000101a31e04 specialized _ArrayBuffer._getElementSlowPath(_:) + 516
2 MyApp 0x00000001019d04eb MyObject.myProperty.setter + 203 (MyObject.swift:706)
3 MyApp 0x000000010192f66e MyViewController.controlTextDidChange(_:) + 190 (MyViewController.swift:166)
...
And the relevant code looks like this:
class MyObject {
var myProperty: [MyObject] {
get {
...
}
set {
let items = newValue.map({ $0.id })
...
}
}
}
What could cause such crashes? Could they be caused by anything other than concurrent access from multiple threads (which I'm quite sure is not the case here, as I only access these arrays from the main thread)?
Just when I think I am finally starting to understand Swift I come across a gotcha like the following:
I have two object, a swiftui display and one of data to be displayed. Ok, sounds easy.
The data is read out of a JSON file so I have a set of arrays and dictionaries. The data is valid when read, it is definitely there, but when I go to display it, its gone. Just vanished. Wasted about a day on this so far, and I’ve seen it before, the inability to pass out of an object an array or dictionary with contents intact.
If I create an array var, and not let the system do it, contents are preserved. So, in the data object I’ll have something like this:
struct DataObject{
var item: [String:Any]
item=JSONData serialized out of memory, and may have say, 12 fields
}
In my SwiftUI module I have:
var item=dataObject.item
dataObject.item now has 0 fields.
I can allocate and initialize a dictionary in DataObject and those elements come through fine. So it seems like the stuff being serialized from JSON is being deleted out from under me.
Hi all,
I just wanted to ask how people were using ModelActor with the Swift 6 language mode enabled. My current implementation involves passing the ModelContainer to my ModelActor, which worked in Sonoma and previous betas of Sequoia, however in the current Beta 3, I get this error:
"Sending 'self.modelContext.container' risks causing data races"
I am a bit confused by this, as from what I understand, ModelContainer conforms to Sendable, so ideally this error should not be thrown. Is this a bug in Beta 3?
Thanks in advance.
Why doesn’t deinit support async? At the end of a test, I want to wipe data from HealthKit, and it’s delete function is asynchronous.
We use XCode 15.2 to build our application, but we found that the app crashes on iOS 12.1.1, while it works without crashing on iOS 12.5.7. We discovered that the crash is related to ImageLoaderMachO::doModInitFunctions. We're not sure what is causing this.
When I run the code, xCode shows me this error "Expressions are not allowed at the top level" While the code is correct and runs in the main.swift file only. And also runs in online compilers. please give me solution...
Hi @all,
I get follow error:
needs -Onone Swift optimization level.
how can I solve this?
thank you for the help
greeting Fabian
I came across a useful repo on GitHub:
https://github.com/GianniCarlo/DirectoryWatcher/blob/master/Sources/DirectoryWatcher/DirectoryWatcher.swift
self.queue = DispatchQueue.global()
self.source = DispatchSource.makeFileSystemObjectSource(fileDescriptor: descriptor, eventMask: .write, queue: self.queue)
self.source?.setEventHandler {
[weak self] in
self?.directoryDidChange()
}
self.source?.setCancelHandler() {
close(descriptor)
}
self.source?.resume()
How do I translate this to OC version? I have an app that was written in OC and I plan to incorporate this directory watcher into the project.
During my analysis of the binary size changes after compiling Swift source code, I discovered symbols with the ".island" suffix. I couldn't find meaningful information about this suffix through my search, so I decided to reach out for assistance.
While comparing the changes in binary size after modifying specific code, I noticed a significant increase (from 33MB to 520MB). Upon analyzing the symbols of the enlarged binary using the nm command, I found the following pattern:
t _$s12{SomeSymbol}WOb
t _$s12{SomeSymbol}WOb.island
t _$s12{SomeSymbol}WOb.island2
t _$s12{SomeSymbol}WOb.island3
When I output the symbols of the binary using nm, I noticed many symbols with the same name but different ".island", ".island2", ".island3" suffixes. Disassembling the binary showed that functions with these suffixes simply delegate calls sequentially: x.island3 -> x.island2 -> x.island1 -> x.
It appears that these symbols serve as delegates for function calls, but I would like to understand why such duplicated functions with these suffixes are generated. Could someone help me to provide some insights on this matter?
'consume' applied to value that the compiler does not support. This is a compiler bug. Please file a bug with a small example of the bug.
public func requestTopicsAndSubTopics() async throws -> (topics: [Topic], subTopics: [String: [SubTopic]]) {
var subTopics = [String: [SubTopic]]()
let topics = try await getTopics().sorted { $0.index < $1.index }
try await withThrowingTaskGroup(of: ([SubTopic], String).self) { [weak self] group in
guard let self else { return }
for topic in topics {
guard let topicId = topic.id else { throw Error.missingId }
group.addTask {
let subTopics = try await self.getSubtopics(topicId: topicId).sorted { $0.name < $1.name }
return (consume subTopics, topicId)
}
}
for try await (resultedSubTopics, topicId) in group {
subTopics.updateValue(resultedSubTopics, forKey: topicId)
}
}
return (consume topics, consume subTopics)
}
I need to decode JSON into a class. The JSON has a field called "Type", and I cannot declare a property with that name in my class since Type is a reserved word.
I tried declaring CodingKeys, but that doesn't work unless I declare EVERY property in the CodingKeys. This class has about a hundred properties and I have others like it, I do not want to do this.
Is there a better solution?
I got the error and I don’t how can I fix it help please
struct MovieDetail: View {
var movie: Movie
let screen = UIScreen.main.bounds
@State private var showSeasonPicker = true
@State private var selectedSeason = 0
var body: some View {
ZStack {
Color.black
.ignoresSafeArea()
ZStack {
VStack {
HStack {
Spacer()
Button() {
// Closing Button
}label: {
Image(systemName: "xmark.circle")
.font(.system(size: 28))
}
}
.padding(.horizontal, 22)
ScrollView (.vertical, showsIndicators: false){
VStack {
StandardHomeMovie(movie: movie)
.frame(width: screen.width / 2.5)
MovieInfoSubheadline(movie: movie)
if movie.promotionHeadline != nil {
Text(movie.promotionHeadline!)
.bold()
.font(.headline)
}
PlayButton(text: "Play", imagename: "play.fill", backgroundColor: .red) {
//
}
CurrentEpisodeInformation(movie: movie)
CastInfo(movie: movie)
HStack(spacing: 60){
SmallVerticalButton(text: "My List", isOnImage: "checkmark", isOffImage: "plus", isOn: true) {
//
}
SmallVerticalButton(text: "Rate", isOnImage: "hand.thumbsup.fill", isOffImage: "hand.thumbsup", isOn: true) {
//
}
SmallVerticalButton(text: "Share", isOnImage: "square.and.arrow.up", isOffImage: "square.and.arrow.up", isOn: true) {
//
}
Spacer()
}
.padding(.leading, 20)
CustomTabSwitcher(tabs: [.episodes, .trailers, .more], movie: movie, showSeasonPicker: $showSeasonPicker, selectedSeason: $selectedSeason)
}
.padding(.horizontal, 10)
}
Spacer()
}
.foregroundStyle(.white)
if showSeasonPicker {
Group {
Color.black.opacity(0.9)
VStack(spacing: 40){
Spacer()
ForEach(0..<(movie.numberOfSeasons ?? 0)) { season in
Button(action: {
self.selectedSeason = (season != 0)
self.showSeasonPicker = false
}, label: {
Text("Season: \(season + 1)")
.foregroundStyle(selectedSeason == season + 1 ? .white : .gray)
.bold()
.font(.title2)
})
}
Spacer()
Button(action: {
self.showSeasonPicker = false
}, label: {
Image(systemName: "xmark.circle.fill")
.foregroundStyle(.white)
.font(.system(size: 40))
.scaleEffect(x: 1.1)
})
.padding(.bottom, 30)
}
}
.ignoresSafeArea()
}
}
}
}
}
#Preview {
MovieDetail(movie: exampleMovie2)
}
struct MovieInfoSubheadline: View {
var movie: Movie
var body: some View {
HStack(spacing: 20){
Image(systemName: "hand.thumbsup.fill")
.foregroundStyle(.white)
Text(String(movie.year))
RatingView(rating: movie.rating)
Text(movie.numberOfSeasonsDisplay)
ZStack{
Text("HD")
.foregroundStyle(.white)
.font(.system(size: 12))
.bold()
Rectangle()
.stroke(.gray, lineWidth: 2)
.frame(width: 30, height: 20)
}
}
.foregroundStyle(.gray)
.padding(.vertical, 6)
}
}
struct RatingView: View {
var rating: String
var body: some View {
ZStack {
Rectangle()
.foregroundStyle(.gray)
Text(rating)
.foregroundStyle(.white)
.font(.system(size: 12))
.bold()
}
.frame(width: 50, height: 20)
}
}
struct CastInfo: View {
var movie: Movie
var body: some View {
VStack(spacing: 3) {
HStack {
Text("Cast: \(movie.cast)")
Spacer()
}
HStack {
Text("Creaters: \(movie.creaters)")
Spacer()
}
}
.font(.caption)
.foregroundStyle(.gray)
.padding(.vertical, 10)
}
}
struct CurrentEpisodeInformation: View {
var movie: Movie
var body: some View {
Group {
HStack {
Text(movie.episodeInfoDisplay)
.bold()
Spacer()
}
.padding(.vertical, 4)
HStack {
Text(movie.episodeDescriptionDisplay)
.font(.subheadline)
Spacer()
}
}
}
}
Usage of multiple async lets crashes the app in a nondeterministic fashion. We are experiencing this crash in production, but it is rare.
0 libswift_Concurrency.dylib 0x20a8b89b4 swift_task_create_commonImpl(unsigned long, swift::TaskOptionRecord*, swift::TargetMetadata<swift::InProcess> const*, void (swift::AsyncContext* swift_async_context) swiftasynccall*, void*, unsigned long) + 384
1 libswift_Concurrency.dylib 0x20a8b6970 swift_asyncLet_begin + 36
We managed to isolate the issue, and we submitted a technical incident (Case-ID: 8007727). However, we were completely ignored, and referred to the developer forums.
To reproduce the bug you need to run the code on a physical device and under instruments (we used swift concurrency). This bug is present on iOS 17 and 18, Xcode 15.1, 15.4 and 16 beta, swift 5 and 6, including strict concurrency.
Here's the code for Swift 6 / Xcode 16 / strict concurrency:
(I wanted to attach the project but for some reason I am unable to)
typealias VoidHandler = () -> Void
enum Fetching { case inProgress, idle }
protocol PersonProviding: Sendable {
func getPerson() async throws -> Person
}
actor PersonProvider: PersonProviding {
func getPerson() async throws -> Person {
async let first = getFirstName()
async let last = getLastName()
async let age = getAge()
async let role = getRole()
return try await Person(firstName: first,
lastName: last,
age: age,
familyMemberRole: role)
}
private func getFirstName() async throws -> String {
try await Task.sleep(nanoseconds: 1_000_000_000)
return ["John", "Kate", "Alex"].randomElement()!
}
private func getLastName() async throws -> String {
try await Task.sleep(nanoseconds: 1_400_000_000)
return ["Kowalski", "McMurphy", "Grimm"].randomElement()!
}
private func getAge() async throws -> Int {
try await Task.sleep(nanoseconds: 2_100_000_000)
return [56, 24, 11].randomElement()!
}
private func getRole() async throws -> Person.Role {
try await Task.sleep(nanoseconds: 500_000_000)
return Person.Role.allCases.randomElement()!
}
}
@MainActor
final class ViewModel {
private let provider: PersonProviding = PersonProvider()
private var fetchingTask: Task<Void, Never>?
let onFetchingChanged: (Fetching) -> Void
let onPersonFetched: (Person) -> Void
init(onFetchingChanged: @escaping (Fetching) -> Void,
onPersonFetched: @escaping (Person) -> Void) {
self.onFetchingChanged = onFetchingChanged
self.onPersonFetched = onPersonFetched
}
func fetchData() {
fetchingTask?.cancel()
fetchingTask = Task {
do {
onFetchingChanged(.inProgress)
let person = try await provider.getPerson()
guard !Task.isCancelled else { return }
onPersonFetched(person)
onFetchingChanged(.idle)
} catch {
print(error)
}
}
}
}
struct Person {
enum Role: String, CaseIterable { case mum, dad, brother, sister }
let firstName: String
let lastName: String
let age: Int
let familyMemberRole: Role
init(firstName: String, lastName: String, age: Int, familyMemberRole: Person.Role) {
self.firstName = firstName
self.lastName = lastName
self.age = age
self.familyMemberRole = familyMemberRole
}
}
import UIKit
class ViewController: UIViewController {
@IBOutlet private var first: UILabel!
@IBOutlet private var last: UILabel!
@IBOutlet private var age: UILabel!
@IBOutlet private var role: UILabel!
@IBOutlet private var spinner: UIActivityIndicatorView!
private lazy var viewModel = ViewModel(onFetchingChanged: { [weak self] state in
switch state {
case .idle:
self?.spinner.stopAnimating()
case .inProgress:
self?.spinner.startAnimating()
}
}, onPersonFetched: { [weak self] person in
guard let self else { return }
first.text = person.firstName
last.text = person.lastName
age.text = "\(person.age)"
role.text = person.familyMemberRole.rawValue
})
@IBAction private func onTap() {
viewModel.fetchData()
}
}
It seems I can declare variables like below in a source file:
private let var1 = 1234
fileprivate let var2 = "abcd"
class MyClass {
// ...
}
So what's the difference between the 2 vars here?
I have a custom localisation function in my project that enforces the inclusion of the bundle parameter (specifically so that Swift packages are forced to include the Bundle.module value).
While migrating to String Catalogs, I noticed that my custom localisation function wasn't being recognised by the automatic extraction that the Swift compiler is doing, but only in my Swift package targets.
Is there a way to set something like LOCALIZED_STRING_MACRO_NAMES in Swift Packages?
This is the error I am continuosly receiving.
@discardableResult func doSomething() -> Bool {
// does something
return true
}
This function can be called in the following ways:
doSomething()
let didSucceed = doSomething()
Is there a way to differentiate the two from inside the doSomething() function, as in, is there a way to know if the caller is using the result?
I want to build a Swift library package that uses modified build of OpenSSL and Curl.
I have already statically compiled both and verified I can use them in an Objective-C framework on my target platform (iOS & iOS Simulator). I'm using XCFramework files that contain the static library binaries and headers:
openssl.xcframework/
ios-arm64/
openssl.framework/
Headers/
[...]
openssl
ios-arm64_x86_64-simulator/
openssl.framework/
Headers/
[...]
openssl
Info.plist
I'm not sure how I'm supposed to set up my Swift package to import these libraries.
I can use .systemLibrary but that seems to use the embedded copies of libssl and libcurl on my system, and I can't figure out how to use the path: parameter to that.
I also tried using a .binaryTarget pointing to the XCFramework files, but that didn't seem to work as there is no module generated and I'm not sure how to make one myself.
At a basic high level, this is what I'm trying to accomplish:
where libcrypto & libssl come from the provided openssl.xcframework file, and libcurl from curl.xcframework
HI, I have a app with Swift Programming language. It is built successfully on my Monterey Intel by using Xcode 14.
I am trying to built same app on Sonoma Silicon arm64 by using Xcode 15.4. But app is failing to build with below errors. Can anyone suggest reason for this?
Copy /Users/testuser/git/agent/out/Darwin/Release/TESTFileProvider.appex/Contents/Resources/swift-nio__NIOFileSystem.bundle /Users/testuser/git/agent/out/Darwin/Release/swift-nio__NIOFileSystem.bundle (in target 'TESTFileProvider' from project 'TEST')
cd /Users/testuser/git/agent/dgagent/agent/macosx/dgc/TEST
builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks /Users/testuser/git/agent/out/Darwin/Release/swift-nio__NIOFileSystem.bundle /Users/testuser/git/agent/out/Darwin/Release/TESTFileProvider.appex/Contents/Resources
error: /Users/testuser/git/agent/out/Darwin/Release/swift-nio__NIOFileSystem.bundle: No such file or directory (in target 'TESTFileProvider' from project 'TEST')
Copy /Users/testuser/git/agent/out/Darwin/Release/TESTFileProvider.appex/Contents/Resources/swift-nio_NIOPosix.bundle /Users/testuser/git/agent/out/Darwin/Release/swift-nio_NIOPosix.bundle (in target 'TESTFileProvider' from project 'TEST')
cd /Users/testuser/git/agent/dgagent/agent/macosx/dgc/TEST
builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks /Users/testuser/git/agent/out/Darwin/Release/swift-nio_NIOPosix.bundle /Users/testuser/git/agent/out/Darwin/Release/TESTFileProvider.appex/Contents/Resources
error: /Users/testuser/git/agent/out/Darwin/Release/swift-nio_NIOPosix.bundle: No such file or directory (in target 'TESTFileProvider' from project 'TEST')