Dive into the world of programming languages used for app development.

All subtopics

Post

Replies

Boosts

Views

Activity

How to add axis labels with DGCharts in Swift?
We are updating our code to work with DGCharts v.4.0 (previously Charts) and our previously working solution for adding labels for the x and y axis (see below) is now no longer working, as "ChartUtils" cannot be found. Does anyone know how this can be achieved with DGCharts? private extension LineChartYAxisRenderer { func renderTitle(title: String, inContext context: CGContext, x: CGFloat) { var foregroundColor = UIColor.darkGray foregroundColor = UIColor.secondaryLabel let attributes: [NSAttributedString.Key: Any] = [ .font: self.axis.labelFont, .foregroundColor: foregroundColor ] // Determine the chart title's y-position. let titleSize = title.size(withAttributes: attributes) let verticalTitleSize = CGSize(width: titleSize.height, height: titleSize.width) let point = CGPoint(x: x, y: ((viewPortHandler.chartHeight - verticalTitleSize.height) / 2)-30) // Render the chart title. ChartUtils.drawText(context: context, text: title, point: point, attributes: attributes, anchor: .zero, angleRadians: .pi / -2) Does anyone know how this can be achieved with DGCharts? We're using Swift5.
0
0
410
Nov ’23
Cpp-Swift Interop fails with conformance to NSObject
I have a project where I m making direct swift calls from cpp as introduced in swift5.9. Below is my swift class whose method is being invoked on cpp. import Foundation public class MySwiftClass { public static func testInterop () -> Void { NSLog("----------- hey --------") } } I m able to successfully invoke 'testInterop()' in cpp with the above class, however if I add conformance to NSObject in the 'MySwiftClass' class, then the swift call fails with the error "No member named 'MySwiftClass' in namespace 'Module2'", where Module2 is my swift target. I m not able to identify why is this happening. Any help?
1
0
343
Nov ’23
After my project is built using Xcode 15 it crashes wherever I have created cpp instance using "new" in OS 11 with arm processor systems.
I am building a project which has swift, cpp and objective - c files. Till now the app was working fine. But now Since the app is built using the newer Xcode version ie Xcode 15, the app is crashing in the BigSur( MacOS 11) using arm64 processor. It works fine in all other OS including OS 11 with x86_64 processor. When I checked the reason for the crash, the crash report points at the place where we created cpp instances in objective c file. My code is as follows _deviceList = new AudioDeviceList(false); // AudioDeviceList is the cpp class and I am creating instance for this in Objective c file mBassTrebleLevelLeft = new BassTreble(512); // BassTreble is the cpp class and I am creating instance for this in Objective c file The crash points at these lines. Can anyone please help me why there is issue with Xcode 15 on creation of cpp instance?
2
0
857
Nov ’23
Error "Type does not conform to Protocol"
I have reduced my error to the following code and am stumped trying to resolve... help would be appreciated. xItem does conform to SCListItem which is the protocol requirement for SCList ... so why am I getting the error? protocol SCList { var items: [ any SCListItem ] { get set } } protocol SCListItem { } class xItem: SCListItem { } class xItemList: SCList { // ERROR Type 'xItemList' does not conform to protocol 'SCList' var items: [ xItem ] = [] }
2
0
325
Nov ’23
How to create and advertise a Bonjour service with Network.framework?
I'm trying to create and advertise a Bonjour service via Network.framework. In Xcode, target, Info tab, I've added the entry to plist: And then written the following code: guard let listener = try? NWListener(service: .init(name: "My Printer Service", type: "_printer._tcp"),using: .tcp) else { return nil } self.listener = listener listener.stateUpdateHandler = { newState in switch newState { case.ready: print("starting") case .failed(let error): print("error: \(error)") default: print(newState) } } listener.start(queue: .main) However, the status is failed with error message: POSIXErrorCode(rawValue: 22): Invalid argument
1
0
895
Nov ’23
Can my app redirect users to a certain Settings screen?
Colleagues, I need your help. I have an swift app-widget and I wish users to have the ability to go to a certain IOS Settings screen, for example to "Display & Brightness". or Night Shift. So, when user taps on widget he will go to Display & Brightness settings screen. Tell me please, is it possible to adjust the code to work this way or does Apple policies not allow redirecting users to a certain screen in ios settings?
1
0
689
Nov ’23
SwiftData ModelContext AutoSave takes about 30 seconds to save the inserted data
I'm a newbie in working with SwiftData and I hope for your help in solving the below issue :") It's about adding new objects into a Model, it takes about 30 seconds to save the data after executing modelContext.insert(). Just run the source code below, tap on "Add" button to add some samples, and then tap on "Delete" button right away. Delete action doesn't work immediately, but it's about 30 seconds after tapping on the "Add" button, it will work - the sample data are deleted properly. I tested and found this issue happens on both Preview and Simulator of: Xcode 15.0 (15A240d) and iOS 17.0 Xcode 15.1 beta (15C5042i) with iOS 17.2 Full source code on GitHub Bike.swift import Foundation import SwiftData @Model class Bike { var name: String init(name: String) { self.name = name } } TestApp.swift import SwiftUI import SwiftData @main struct TestApp: App { var body: some Scene { WindowGroup { BikeListView() } .modelContainer(for: Bike.self) } } BikeListView.swift import SwiftUI import SwiftData struct BikeListView: View { @Environment(\.modelContext) var modelContext @Query var bikes: [Bike] var body: some View { VStack { HStack(spacing: 30) { Button { addSamples() } label: { Text("Add") } Button { deleteSamples() } label: { Text("Delete") } } List { ForEach(bikes) { eachBike in Text(eachBike.name) } } } } func addSamples() { let bikeOne = Bike(name: "One") let bikeTwo = Bike(name: "Two") modelContext.insert(bikeOne) modelContext.insert(bikeTwo) } func deleteSamples() { try? modelContext.delete(model: Bike.self) } } #Preview { do { let modelConfig = ModelConfiguration(isStoredInMemoryOnly: true) let modelContainer = try ModelContainer(for: Bike.self, configurations: modelConfig) return BikeListView() .modelContainer(modelContainer) } catch { fatalError("Content View's Preview") } } Thanks for reading and I'm looking forward to your help.
2
0
1.3k
Nov ’23
Xcode 15.1 & iOS 17.2: SwiftData ModelContext Delete: It's only possible to delete the data after it has been inserted for about 30 seconds
I'm a newbie in working with SwiftData and I hope for your help in solving the below issue :") It's about deleting the objects into a Model by ModelContext.delete(). It's only possible to delete the data after it has been inserted for about 30 seconds. Just run the source code below, tap on "Add" button to add some samples, and then tap on "Delete" button right away. At this time, Delete action doesn't work. You have to wait about 30 seconds, then tap on "Delete" button, it will work - the sample data are deleted properly. I tested this issue on Xcode 15.1 beta (15C5042i) and found that: This issue always happens on Preview w/ iOS 17 or iOS 17.2. This issue doesn't happen on Simulator w/ iOS 17 BUT it happens on Simulator w/ iOS 17.2 Is this an issue of iOS 17.2 ? Full source code on GitHub Bike.swift import Foundation import SwiftData @Model class Bike { var name: String init(name: String) { self.name = name } } TestApp.swift import SwiftUI import SwiftData @main struct TestApp: App { var body: some Scene { WindowGroup { BikeListView() } .modelContainer(for: Bike.self) } } BikeListView.swift import SwiftUI import SwiftData struct BikeListView: View { @Environment(\.modelContext) var modelContext @Query var bikes: [Bike] var body: some View { VStack { HStack(spacing: 30) { Button { addSamples() } label: { Text("Add") } Button { deleteSamples() } label: { Text("Delete") } } List { ForEach(bikes) { eachBike in Text(eachBike.name) } } } } func addSamples() { let bikeOne = Bike(name: "One") let bikeTwo = Bike(name: "Two") modelContext.insert(bikeOne) modelContext.insert(bikeTwo) } func deleteSamples() { try? modelContext.delete(model: Bike.self) } } #Preview { do { let modelConfig = ModelConfiguration(isStoredInMemoryOnly: false) let modelContainer = try ModelContainer(for: Bike.self, configurations: modelConfig) return BikeListView() .modelContainer(modelContainer) } catch { fatalError("Content View's Preview") } } Thanks for reading and I'm looking forward to your help.
2
0
1.2k
Nov ’23
How to enable clicks through window toolbar
I'm currently building a MacOS app using react-native-macos, since I don't have any experience in Swift or Objective-C. The interface in the screenshot below is therefore faking a titlebar. The real titlebar is set to be transparent and overlays the whole application. The problem that I have is that the toolbar blocks clicks from going through. If I try to click the plus button on the right, nothing happens. Mouse hover is still noticed, but clicks don't go through. How do I get the clicks to be registered by React? In the best case with the window still being draggable. The buttons in the toolbar change, so the click area changes as well. I'm setting my window in the AppDelegate.swift and my code basically looks like this: func applicationDidFinishLaunching(_ aNotification: Notification) { let jsCodeLocation: URL #if DEBUG jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index") #else jsCodeLocation = Bundle.main.url(forResource: "main", withExtension: "jsbundle")! #endif let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "JiraTimeTracker", initialProperties: nil, launchOptions: nil) let rootViewController = NSViewController() rootViewController.view = rootView // Create the application window window = NSWindow( contentRect: NSRect(x: 0, y: 0, width: 1, height: 1), styleMask: [.titled, .closable, .miniaturizable, .resizable], backing: .buffered, defer: false) window.titlebarAppearsTransparent = true window.titleVisibility = .hidden window.toolbarStyle = .unified window.styleMask.insert(NSWindow.StyleMask.fullSizeContentView) window.contentViewController = rootViewController window.center() window.isReleasedWhenClosed = false window.makeKeyAndOrderFront(self) // Add a toolbar to the window to increase its titlebar height window.toolbar = NSToolbar() let screen: NSScreen = NSScreen.main! let midScreenX = screen.frame.midX let posScreenY = 200 let origin = CGPoint(x: Int(midScreenX), y: posScreenY) let size = CGSize(width: 700, height: 800) let frame = NSRect(origin: origin, size: size) window.setFrame(frame, display: true) } The Apple docs say that you can: Use the contentLayoutRect or the contentLayoutGuide to lay out views underneath the title bar–toolbar area. I tried doing this, but I couldn't get it to work due to my limited Swift knowledge. I also don't know if this would still allow dragging. I guess this is only used to prevent content from being underneath the titlebar (but that's what I want)? A different idea that I got is to send an event to React on each click in the toolbar. I know where the cursor is, so I could then manually recreate the click event. This should be possible with native modules but again, due to my limited knowledge I'm not quite sure if this is even possible. I also found this answer which may be related, but the solution there is written in Swift 4.2 and I wasn't able to adjust this to my Swift version yet. Any help is really appreciated!
0
0
287
Nov ’23
Get the number of Apple Silicon performance cores in Python
Simple question, I want to determine the number of performance cores in an Python script (better a Python app frozen with PyInstaller, which could make a difference). there are some ways to get the number of CPUs/cores like os.cpu_count(), multiprocessing.cpu_count() or psutil.cpu_count() (the later allowing discrimination between physical and virtual cores). However, Apple Silicon CPUs are separated into performance and efficiency cores, which you can get with (e.g.) sysctl hw.perflevel0.logicalcpu_max for performance and sysctl hw.perflevel1.logicalcpu_max for efficiency cores. Is there any way to get this in Python besides running sysctl and get the shell output? Maybe using the pyobjc package?
0
0
820
Nov ’23
makeFileSystemObjectSource does not monitor changes made with nano
I have folder monitoring code using makeFileSystemObjectSource. The events are triggered for everything else, but not for when I edit a file with nano terminal command. Am I doing something wrong? Is it a bug? Is this intended and unfixable? Code sample: monitoredFolderFileDescriptor = open(currentlyMonitoredPath, O_EVTONLY) folderMonitorSource = DispatchSource.makeFileSystemObjectSource(fileDescriptor: monitoredFolderFileDescriptor, eventMask: .all, queue: .main) folderMonitorSource?.setEventHandler { // ... } folderMonitorSource?.setCancelHandler { // ... } folderMonitorSource?.resume()
2
0
774
Nov ’23
Not able to set Origin in request header in WKWebview
I have an iOS app centred around a WKWebView loading local web assets with loadFileURL. The WKWebView communicates over HTTPS to a backend API. We have made some changes at back end and due to that we need to send some app specific values for Origin of request header. In case my case value is getting replace by some default value as file://. I'm getting CORS issue while loading my application. Can I change the origin of the WKWebView to xyz to avoid browsers from querying the API?
0
0
330
Nov ’23
Amplify/GraphQL - Issue getting full data with one-to-one relationship
Just to give some background, we have two tables with a one to one relationship. So, Table A has a one-to-one relationship with Table B. With amplify, I see that Table A has a foreign key for Table B. When we do a query to fetch a list of items using a filter, we call for a list of items from Table A. With graphQL, since we have the @hasOne key, the data from table B will be nested inside each row from table A data. When I test the raw graphQL query itself on amplify's console, it's fine, but on xcode, the nested data from Table B is showing up as null. Has anyone have an idea on what is causing this? If you need clarification, do not hesitate to let me know! Some things I have tried are here: https://docs.amplify.aws/cli/migration/lazy-load-custom-selection-set/ Now, I have set "generateModelsForLazyLoadAndCustomSelectionSet" to true, but it caused a compilation error. One of the message is that "LazyReference" has not been found. So, I've been having trouble implementing one of the suggestions. The main problem is that, how can I have data from table B show up in my results when I query for a list of items from table A? This is only happening with 'hasOne' relationship.
0
0
319
Nov ’23
Password AutoFill not working WKWebView
I've implemented Password AutoFill for our webpage. It's working fine in safari browser and SFSafariViewController Safari browser Same way, in our mobile app, we are using a web-based login page. For the login, we are using WKWebView, but in WKWebView the popup is not showing, instead, it’s showing the normal keyboard. WKWebView - App Already configured Associated Domains under Capability. webcredentials:prod.auth.TestDomain.org
0
1
843
Nov ’23
With Xcode15, app crash when call presentLimitedLibraryPicker
First, App has linked with PhotosUI and Photos. And, this problem never happened when complied with Xcode14.1 and Swift. New APP is compiled with Xcode15.0.1. Code is not changed. Step: Set access "Selected Photos" for APP. Restart APP. Try to access photos with PHPhotoLibrary functions , and then a system dialog appears. There are two buttons: "Select More Photos..." and "Keep Current Selection". Choose "Keep Current Selection". (If choose "Select More Photos...", the app will not crash.) Call "presentLimitedLibraryPicker(from controller: UIViewController)" Crash log: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PHPhotoLibrary presentLimitedLibraryPickerFromViewController:]: unrecognized selector sent to instance 0x1064d66f0'
2
0
905
Nov ’23
Function call when exiting app, but not locking phone
I am currently trying to develop my first app in xcode and I want a function to run whenever the app i exited. I.e. switching to another app or going to the home screen. But if the phone is locked while in the app I do not want the function to run. I currently use the sceneDelegate and sceneDidEnterBackground, that works for running the function when exiting the app, but it also runs when I lock the phone. I do not want that to happen. How do I go about implementing this feature? In addition I also want to have a "live notification" showing on the lock screen if you lock the phone from the app, I have not been able to find out how that works either.
0
1
177
Nov ’23
Swift - Correct syntax for "onChange" in Apple's sample code?
Hi everyone, I wanted to create a Table and make its rows sortable. For lack of better ideas how to do this I followed Apple's example here [https://developer.apple.com/documentation/swiftui/table) Here's the code in question: @State private var sortOrder = [KeyPathComparator(\Person.givenName)] var body: some View { Table(people, sortOrder: $sortOrder) { TableColumn("Given Name", value: \.givenName) TableColumn("Family Name", value: \.familyName) TableColumn("E-Mail address", value: \.emailAddress) } .onChange(of: sortOrder) { people.sort(using: $0) } } } To my amazement Xcode shows this message: 'onChange(of:perform:)' was deprecated in macOS 14.0: Use onChange with a two or zero parameter action closure instead. I find this message rather annoying. Do you have any ideas how to fix this?
1
0
837
Nov ’23