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

All subtopics

Post

Replies

Boosts

Views

Activity

SPM show-dependencies broken
I have a Package.swift // swift-tools-version: 5.9 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "SharedUI", defaultLocalization: "en_US", platforms: [.iOS(.v16)], products: [ .library( name: "SharedUI", targets: [ "AppTheme", ] ), ], dependencies: [ .package(url: "https://github.com/apple/swift-markdown.git", "0.2.0"..<"0.3.0"), ], targets: [ .target( name: "AppTheme", dependencies: [ .product(name: "Markdown", package: "swift-markdown"), ], path: "AppTheme" ), ] ) Run swift package show-dependencies shows error yuantong-macbookpro2:Downloads yuantong$ swift package show-dependencies Fetching https://github.com/apple/swift-markdown.git from cache Fetched https://github.com/apple/swift-markdown.git (0.67s) error: Couldn’t get the list of tags: fatal: cannot use bare repository '/Users/yuantong/Downloads/.build/repositories/swift-markdown-b692ce3c' (safe.bareRepository is 'explicit') which I think used to work before Xcode 15.
8
4
1.9k
Feb ’24
local doc save and iCloud data in same app
I have app that is using container for small settings data and iCloud for larger storage, but I also want to be able to save to local documents folder. When I do that the url that is created is not local docs, but: path: file:///var/mobile/Containers/Data/Application/85A8B8C9-C0C3-4843-A74C-5A951F593790/Documents/Dialog08:45,%2022%20Feb%202024 Here is code using to save to local docs folder. func saveDataToFile(data: String) { //file will be datetimedialog let formatter = DateFormatter() formatter.dateFormat = "HH:mm, d MMM y" var dateTime = Date.getCurrentDate() dateTime = formatter.string(from: Date.now) var saveFilename = "Dialog" saveFilename.append(dateTime) let path = getDocumentsDirectory().appendingPathComponent(saveFilename) print("path: \(path)") // let fileURL = URL(fileURLWithPath: data, relativeTo: path) do { try data.write(to: path, atomically: true, encoding: String.Encoding.utf8) } catch { print(error.localizedDescription) } } func getDocumentsDirectory() -> URL { let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) return paths[0] }
1
0
668
Feb ’24
AVAudioRecorder currentTime different than AVPlayer.duration
I have a small audio app that records audio and then the user can play back. I am having an issue trying to display elapsed and total times. When I record the file, I use the audiorecorder.currentTime to get the recording length but when I load it in AVPlayer, it shows a different length. It is usually around 200ms off but not always. When comparing the raw files. the AVPlayer does seem to report the correct time (length). I am using a timer when recording that fires every 100ms since I don't think AVAudioRecorder has an observer like the AVPlayer, that updates the recording time using the audiorecorder.currentTime. I've checked out a number of things online and all of the example code I've found seems to have the same issue with the recorded time and player duration not being the same (The examples I have show the recorded time but never show the playback length but I manually loaded the file to check the playback length and it was always longer than the recorded display length) but there has to be a way to do this properly? Hopefully someone has some ideas or can tell me of a way they worked around this. I am recording using the following settings; let settings = [ AVFormatIDKey: Int(kAudioFormatMPEG4AAC), AVSampleRateKey: 16000, AVNumberOfChannelsKey: 1, AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue ]
0
0
553
Feb ’24
How can I reverse USDZ animation in realityKit
How can i play a USDZ entity animation in reverse? I have tried to put a negative value to the speed as I was doing in SceneKit to make the animation reverse play but it did not work. here is my code: import SwiftUI import RealityKit struct ImmersiveView: View { @State var entity = Entity() @State var openDoor: Bool = true var body: some View { RealityView { content in if let mainDoor = try? await Entity(named: "Door.usdz") { if let frame = mainDoor.findEntity(named: "DoorFrame") { frame.position = [0, 0, -8] frame.orientation = simd_quatf(angle: (270 * (.pi / 180)), axis: SIMD3(x: 1, y: 0, z: 0)) content.add(frame) entity = frame.findEntity(named: "Door")! entity.components.set(InputTargetComponent(allowedInputTypes: .indirect)) entity.components.set(HoverEffectComponent()) let entityModel = entity.children[0] entityModel.generateCollisionShapes(recursive: true) } } } .gesture( SpatialTapGesture() .targetedToEntity(entity) .onEnded { value in print(value) if openDoor == true { let animController = entity.playAnimation(entity.availableAnimations[0], transitionDuration: 0 , startsPaused: true) animController.speed = 1.0 animController.resume() openDoor = false } else { let animController = entity.playAnimation(entity.availableAnimations[0], transitionDuration: 0 , startsPaused: true) animController.speed = -1.0 // it does not work to reverse animController.resume() openDoor = true } } ) } } The Door should open with first click which is already happening and close with second click which is not happening as it does not reverse play the animation
5
0
1.4k
Feb ’24
Swift TableView: Saving Text from TextField
For the past few months, I’ve been learning about Swift coding. I’m relatively new to the coding field so this may seem trivial to some. Here’s what I’m trying to do: I cannot get the data saved from regular textboxes to appear in the table I've designed on the storyboard. It is clearly saving something to the table rows but I cannot see it. I've looked all over the web but most examples are from old versions of swift/deprecated versions of Xcode and are not applicable. Basically, I’m designing an app for my company that allows quick and easy saving of users that call; I would be able to save their company, name, phone, userid, etc, the app saves it into the table And allows me to reference it later. I'm using core data and I’ve attached all of the code to the appropriate storyboard fields. any insight or errors someone could point out would be very helpful. Here’s my code: import Cocoa import SwiftData import SwiftUI class User: NSManagedObject, Identifiable { let id = UUID() //compatibility @NSManaged public var company: String @NSManaged public var name: String @NSManaged public var phone: String @NSManaged public var uid: String @NSManaged public var cid: String @NSManaged public var tvid: String @NSManaged public var tvpwd: String @NSManaged public var notes: String } class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate { @IBOutlet weak var companyTextField: NSTextField! @IBOutlet weak var nameTextField: NSTextField! @IBOutlet weak var phoneTextField: NSTextField! @IBOutlet weak var uidTextField: NSTextField! @IBOutlet weak var cidTextField: NSTextField! @IBOutlet weak var tvidTextField: NSTextField! @IBOutlet weak var tvpwdTextField: NSTextField! @IBOutlet weak var notesTextField: NSTextField! @IBOutlet weak var tableView: NSTableView! var users = [User]() override func viewDidLoad() { super.viewDidLoad() tableView.dataSource = self tableView.delegate = self } @IBAction func saveButtonClicked(_ sender: NSButton) { let user = User() users.append(user) tableView.reloadData() } // MARK: - NSTableViewDataSource func numberOfRows(in tableView: NSTableView) -> Int { return users.count } // MARK: - NSTableViewDelegate func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { let user = users[row] guard let cell = tableView.makeView(withIdentifier: tableColumn!.identifier, owner: self) as? NSTableCellView else { return nil } switch tableColumn?.identifier.rawValue { case "company": cell.textField?.stringValue = user.company case "name": cell.textField?.stringValue = user.name case "phone": cell.textField?.stringValue = user.phone case "uid": cell.textField?.stringValue = user.uid case "cid": cell.textField?.stringValue = user.cid case "tvid": cell.textField?.stringValue = user.tvid case "tvpwd": cell.textField?.stringValue = user.tvpwd case "notes": cell.textField?.stringValue = user.notes default: return nil } return cell } } ![]
2
0
822
Feb ’24
macOS App Launch Fails with RunningBoard Entitlement Errors on WKWebView Video Play
I am developing a macOS application and have encountered an issue with entitlements that I am unable to resolve. The error emerges from the RunningBoard service when I try to play a video in a WKWebView. Here is the specific error: Error acquiring assertion: &lt;Error Domain=RBSServiceErrorDomain Code=1 "(originator doesn't have entitlement com.apple.runningboard.assertions.webkit AND originator doesn't have entitlement com.apple.multitasking.systemappassertions)" UserInfo={NSLocalizedFailureReason=(originator doesn't have entitlement com.apple.runningboard.assertions.webkit AND originator doesn't have entitlement com.apple.multitasking.systemappassertions)}&gt; I'm seeking answers to the following questions: What do the entitlements com.apple.runningboard.assertions.webkit and com.apple.multitasking.systemappassertions refer to specifically? How can I resolve the errors associated with the absence of these entitlements? This problem appears to affect many users, yet a public solution has not been identified. I've tried adding NSMicrophoneUsageDescription and NSCameraUsageDescription to my Info.plist, as suggested here, but to no avail. An apparent Apple employee suggested adding Background Modes to capabilities here, but such options do not exist. Numerous similar issues are documented online, but none provide a resolution. When I attempt to include the entitlements com.apple.runningboard.assertions.webkit and com.apple.multitasking.systemappassertions as indicated in the logs, my application fails to start, resulting in the following error message: Could not launch “My App Name” Runningboard has returned error 5. Please check the system logs for the underlying cause of the error. The error logs are extensive and include: Could not launch “Quick Music Bar” Domain: IDELaunchErrorDomain Code: 20 Recovery Suggestion: Runningboard has returned error 5. Please check the system logs for the underlying cause of the error. User Info: { DVTErrorCreationDateKey = "2024-02-24 06:26:22 +0000"; DVTRadarComponentKey = 968756; IDERunOperationFailingWorker = IDELaunchServicesLauncher; } -- The operation couldn’t be completed. Launch failed. Domain: RBSRequestErrorDomain Code: 5 Failure Reason: Launch failed. -- Launchd job spawn failed Domain: NSPOSIXErrorDomain Code: 153 -- Event Metadata: com.apple.dt.IDERunOperationWorkerFinished : { "device_model" = "Mac14,10"; "device_osBuild" = "14.3.1 (23D60)"; "device_platform" = "com.apple.platform.macosx"; "dvt_coredevice_version" = "355.7.7"; "dvt_mobiledevice_version" = "1643.60.2"; "launchSession_schemeCommand" = Run; "launchSession_state" = 1; "launchSession_targetArch" = arm64; "operation_duration_ms" = 113; "operation_errorCode" = 20; "operation_errorDomain" = IDELaunchErrorDomain; "operation_errorWorker" = IDELaunchServicesLauncher; "operation_name" = IDERunOperationWorkerGroup; "param_debugger_attachToExtensions" = 0; "param_debugger_attachToXPC" = 1; "param_debugger_type" = 3; "param_destination_isProxy" = 0; "param_destination_platform" = "com.apple.platform.macosx"; "param_diag_MainThreadChecker_stopOnIssue" = 0; "param_diag_MallocStackLogging_enableDuringAttach" = 0; "param_diag_MallocStackLogging_enableForXPC" = 1; "param_diag_allowLocationSimulation" = 1; "param_diag_checker_tpc_enable" = 1; "param_diag_gpu_frameCapture_enable" = 0; "param_diag_gpu_shaderValidation_enable" = 0; "param_diag_gpu_validation_enable" = 0; "param_diag_memoryGraphOnResourceException" = 0; "param_diag_queueDebugging_enable" = 1; "param_diag_runtimeProfile_generate" = 0; "param_diag_sanitizer_asan_enable" = 0; "param_diag_sanitizer_tsan_enable" = 0; "param_diag_sanitizer_tsan_stopOnIssue" = 0; "param_diag_sanitizer_ubsan_stopOnIssue" = 0; "param_diag_showNonLocalizedStrings" = 0; "param_diag_viewDebugging_enabled" = 1; "param_diag_viewDebugging_insertDylibOnLaunch" = 1; "param_install_style" = 0; "param_launcher_UID" = 2; "param_launcher_allowDeviceSensorReplayData" = 0; "param_launcher_kind" = 0; "param_launcher_style" = 99; "param_launcher_substyle" = 8192; "param_runnable_appExtensionHostRunMode" = 0; "param_runnable_productType" = "com.apple.product-type.application"; "param_structuredConsoleMode" = 1; "param_testing_launchedForTesting" = 0; "param_testing_suppressSimulatorApp" = 0; "param_testing_usingCLI" = 0; "sdk_canonicalName" = "macosx14.2"; "sdk_osVersion" = "14.2"; "sdk_variant" = macos; } -- System Information macOS Version 14.3.1 (Build 23D60) Xcode 15.2 (22503) (Build 15C500b) Timestamp: 2024-02-24T15:26:22+09:00 The system information is as follows: macOS Version 14.3.1 (Build 23D60), Xcode 15.2 (22503) (Build 15C500b), Timestamp: 2024-02-24T15:26:22+09:00 Has anyone else encountered this issue, or can anyone provide guidance on how to proceed?
2
0
2.0k
Feb ’24
Termination reason: Namespace SIGNAL, Code 11 Segmentation fault: 11
I have Sims 4 downloaded onto my macbook and it has been working just fine until it started closing the application out of nowhere. A full crash report would come up everytime yet I do not understand code and need to know what the issue is. The game opens, and for a few minutes works until it simply closes out of nowhere. Here is the crash report: Crashed Thread: 22 Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: KERN_INVALID_ADDRESS at 0x0000000164420150 Exception Codes: 0x0000000000000001, 0x0000000164420150 Termination Reason: Namespace SIGNAL, Code 11 Segmentation fault: 11 Terminating Process: exc handler [1224] VM Region Info: 0x164420150 is not in any region. Bytes after previous region: 344401 Bytes before following region: 18562736 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL __LINKEDIT 164364000-1643cc000 [ 416K] r--/rw- SM=COW ...thon370.dylib ---&gt; GAP OF 0x1208000 BYTES __TEXT 1655d4000-1655d8000 [ 16K] r-x/rwx SM=COW ...process.dylib Thread 22 Crashed: 0 Simulation.dylib 0x1656e5060 0x16560c000 + 888928 1 Simulation.dylib 0x1656e5144 0x16560c000 + 889156 2 Simulation.dylib 0x165b51274 0x16560c000 + 5526132 3 libsystem_pthread.dylib 0x19152106c _pthread_start + 148 4 libsystem_pthread.dylib 0x19151be2c thread_start + 8 Thread 22 crashed with ARM Thread State (64-bit): x0: 0x0000000000000000 x1: 0xffffffffffffffff x2: 0x0000000000000001 x3: 0x0000000000000001 x4: 0x0000000000000000 x5: 0x0000000001e84800 x6: 0x00000002a84b6af0 x7: 0x0000000170a76778 x8: 0x000000016441ff68 x9: 0x00000001ec891f40 x10: 0x0000000000000011 x11: 0x00000000000002ee x12: 0x0000000000000008 x13: 0x0000000000000004 x14: 0x0000000100000000 x15: 0x0000000000000000 x16: 0x00000001914e274c x17: 0x00000001f16c86e8 x18: 0x0000000000000000 x19: 0x0000000164436620 x20: 0x0000000164436628 x21: 0x0000000164436668 x22: 0x0000000000000002 x23: 0x000000016440fb60 x24: 0x00000001664bce10 x25: 0x00000000db89ff23 x26: 0x00000000811c9dc5 x27: 0x0000000166498000 x28: 0x0000000166498000 fp: 0x0000000170a76f90 lr: 0x11168001656e5144 sp: 0x0000000170a76f40 pc: 0x00000001656e5060 cpsr: 0x60001000 far: 0x0000000164420150 esr: 0x92000007 (Data Abort) byte read Translation fault
1
0
1.6k
Feb ’24
error when trying to decrypt an RSA 2048 encrypted string
Getting the below error when trying to decrypt an encrypted string sent from my server. Printing description of error: ▿ Optional&lt;Unmanaged&lt;CFErrorRef&gt;&gt; ▿ some : Unmanaged&lt;CFErrorRef&gt; - _value : Error Domain=NSOSStatusErrorDomain Code=-50 "&lt;SecKeyRef algorithm id: 1, key type: RSAPrivateKey, version: 4, 2048 bits (block size: 256), addr: 0x600000cb16c0&gt;: sign - input buffer bad size (344 bytes)" UserInfo={numberOfErrorsDeep=0, NSDescription=&lt;SecKeyRef algorithm id: 1, key type: RSAPrivateKey, version: 4, 2048 bits (block size: 256), addr: 0x600000cb16c0&gt;: sign - input buffer bad size (344 bytes)} I generated the RSA 2048 public private key pairs using private func getRsaKeyPair()-&gt;(String,SecKey)?{ let publicKeyAttr: [NSObject: Any] = [ kSecAttrIsPermanent: true, kSecAttrApplicationTag: "com.appname.one.rsa.public".data(using: String.Encoding.utf8)!, kSecClass: kSecClassKey, kSecReturnData: kCFBooleanTrue as Any] let privateKeyAttr: [NSObject: Any] = [ kSecAttrIsPermanent:true, kSecAttrApplicationTag:"com.appname.one.rsa.private".data(using: String.Encoding.utf8)!, kSecClass: kSecClassKey, kSecReturnData: kCFBooleanTrue as Any] var keyPairAttr = [NSObject: Any]() keyPairAttr[kSecAttrKeyType] = kSecAttrKeyTypeRSA keyPairAttr[kSecAttrKeySizeInBits] = 2048 keyPairAttr[kSecPublicKeyAttrs] = publicKeyAttr keyPairAttr[kSecPrivateKeyAttrs] = privateKeyAttr var error: Unmanaged&lt;CFError&gt;? = nil let privateKey = SecKeyCreateRandomKey(keyPairAttr as CFDictionary, &amp;error) if let privateKey { var resultPublicKey: AnyObject? let statusPublicKey = SecItemCopyMatching(publicKeyAttr as CFDictionary, &amp;resultPublicKey) if statusPublicKey == noErr { if let publicKey = resultPublicKey as? Data { return(publicKey.base64EncodedString(), privateKey) } } } return nil } i then sent the public key to my node js server which then returned me a string encrypted with the said public key. I decrypt it as follows guard let key = data.encStr?.data(using: .utf8) else{ return } print("encStr Size: \(key.count) bytes") var error: Unmanaged&lt;CFError&gt;? = nil if let plaintext = SecKeyCreateDecryptedData(privateKey, .rsaEncryptionPKCS1 , key as CFData, &amp;error) as? Data{ print("HURRAY:\(plaintext)") if let plainTextStr = String(data: plaintext, encoding: .utf8){ print(plainTextStr) } }else{ print(error.debugDescription) } But i get the above mentioned error when decrypting using my private key.
1
1
630
Feb ’24
ITMS-90109: This bundle is invalid - The key UIRequiredDeviceCapabilities in the Info.plist may not contain values that would prevent this application from running on devices that were supported by previous versions.
So I have an app live in the app store all good, however I am now developing an update to it that adds the ability to allow photos to be used and that requires that the app gets an additional access to the camera roll. Now on upload to testflight I get this error emailed to me, not in the interface: ITMS-90109: This bundle is invalid - The key UIRequiredDeviceCapabilities in the Info.plist may not contain values that would prevent this application from running on devices that were supported by previous versions. To me that is saying that I cant add new features to an app that requires additional permissions. Is that correct? How can I get around this, will my app get rejected when I submit it due to this, or is it just an information item?
5
0
2.0k
Feb ’24
iPad 10th generation top header text becomes invisible only in app initial launch.
I’m creating a hybrid app using Swift and Angular. Angular content is loading on top of the Native Swift WkWebView. Starting from iPad 10th generation only in the app initial launch header area become invisible(invisible means header text becomes white). But once I send the app to background and return to foreground header text becomes black and it will show without problem. I would really like to know whether this is a OS problem and if so is there any pro-grammatical solution for this? if anyone can guide me to proper way fix this much a appreciated!!! Environment: ・Device: iPad 10th generation ・OS:iPad OS 17.3.1 ・Native App : Swift 5
1
0
693
Feb ’24
Passing Cpp object to swift
I have a macOS app project implementing the direct Cpp-swift interop mechanism. The project some cpp classes and few Swift class. I wanted to pass a cpp object to a swift function as parameter, so I can use it in my swift code. But the documentation is not very clear on how to do this. Can some please share a code snippet explaining how can I achieve this? I have tried the below code, but it is giving linker error. Swift code: import StClass_modulemap public class SwiftClass { .. public static func getCppObj (pObj: inout StClass) -> Void { ... } } Cpp code: #include "Student.hpp" #include "StClass.hpp" #include <InteropLib-Swift.h> using namespace InteropLib; void Student::Introduce() { //creating cpp to be passed to swift // StClass StObj(50); // Teacher::getCppObj(StObj); std::cout<< "header included in hpp " <<std::endl; } calling Student::Introduce is giving a linker error for StClass
0
0
361
Feb ’24
Issue with UIDatePicker causing Application Crash
Hi everyone, I'm encountering a frustrating issue with UIDatePicker in my iOS application and would greatly appreciate any insights or assistance in resolving it. Description: Upon adding a UIDatePicker to my UIViewController using the drag-and-drop method, the date picker functions correctly, allowing users to select dates without any issues. However, when attempting to change the year by tapping on the month and year view, the application crashes with the following error message: Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]' This issue occurs consistently with both the compact and inline styles of UIDatePicker. Steps to Reproduce: Add a UIDatePicker to a UIViewController using the Interface Builder. Run the application on a device or simulator. Open the UIDatePicker. Tap on the month and year view to change the year. Expected Behavior: The application should allow users to change the year in the UIDatePicker without crashing. Actual Behavior: The application crashes with the error message mentioned above when attempting to change the year. Additional Information: This issue occurs regardless of the date picker's configuration or settings. I've tried various troubleshooting steps, including checking for conflicts with other components and reviewing the view hierarchy, but have been unable to identify the root cause of the problem. If anyone has encountered a similar issue or has any suggestions for resolving this issue, I would be grateful for your assistance. Attached screenshots of implementation and stack trace.
4
0
640
Feb ’24
Xcode + NSLocalizedString + String Catalogs + Macros
For quite a while, I have been using a somewhat simple-minded technique to provide semi-automatic localizations for strings used within a few of my apps. Here is the gist: Create an enumeration with RawValue of String that conforms to LocalizedRawRepresentable. Use this enum to associate a "key" with a string (default localization) Run a script that parses all Swift code looking for the enumerations that conform to LocalizedRawRepresentable and create/update a Localized.strings file. There were some minor issues, as it isn't easy to parse a complex Swift set of sources, but it got the job done. Simple example: enum L: String, LocalizedRawRepresentable { case fileNotFound = "File not found" } // [ ... ] if !FileManager.default.fileExists(at path: String) { print(L.fileNotFound.localized) } Well, we now have Xcode 15, and we have some new features: Macros - these things can parse Swift sources with excruciating detail A new ***** called String Catalogs Xcode supports these String Catalogs by automatically detecting localizations and creating, updating, and deleting entries into Strings Catalog automatically. So, it was time to update my simplistic LocalizedRawRepresentable and update it to support the String Catalogs! So, with my contrived example above, I spent quite a lot of time reading up and experimenting with the new Swift macros and created a macro that will make localizations much easier (so I thought...): @LocalizedStrings() enum L { private enum Strings: String { case fileNotFound = "File not found" } } The macro takes this modified enumeration and expands it to the following code: @LocalizedStrings() enum L { private enum Strings: String { case fileNotFound = "File not found" } static let fileNotFound = NSLocalizedString("fileNotFound", tableName: nil, bundle: .main, value: "File not found") } extension L: LocalizedStrings { } What I expected: Xcode would pick up the NSLocalizedStrings() generated code, and insert it into the strings catalog, and all of my work is done... no scripts needed! What I got... Xcode did not detect the generated code, and nothing was added, modified, or deleted from the strings catalog. So, I have a few questions: Is my code deficient in some way? Is there something I need to add to my generated code that would let Xcode know there are localizations to be detected? Is this an intentional limitation of Xcode's auto-detection of localizations for string catalogs to ignore generated code in its detection? (I'd hate to think I went through all this work for Xcode to simply ignore what I've done...!) Is this an accidental omission of Xcode that may be "fixed" in a future release? Right now, I can use the expanded macro to cut/paste the localization keys and values into the strings catalog, but I hoped that Swift macros plus Xcode auto-detection of localizations would have made this process nearly automatic. Does anybody have any suggestions?
2
0
1.4k
Feb ’24