Build, test, and submit your app using Xcode, Apple's integrated development environment.

Xcode Documentation

Posts under Xcode subtopic

Post

Replies

Boosts

Views

Activity

Trouble Seeing print debug statements
I am working on an XCode project and I have some Swift functions within a helper functions file. This file has some functions declared that create 3 global variables. These global variables are then used in various views throughout the app. In the functions, there are print statements for when it catches an error. However, when I run the app and I get an error that stems from this file, there are no print statements. How can I have this print statements show up in the debug console?
1
0
395
Mar ’25
Preview broken
Hello, I am doing the SwiftUI tutorial with Xcode 16.2 For the watch app the simulator working fine but the preview keep saying “This app cannot run on the selected target device.” while the preview is working …… For the macOS part the simulator working fine but the preview is totally broken with -> ”ContentView.swift” not found in any targets. While it is correctly added to the target … Please fix or make tutorial clear.
0
0
150
Feb ’25
Cannot assign build target to usdz file
I’m working in the app playground and want to add my usdz file but when i drag drop the file to my main folder i cannot add target to it which leads to a resource not found error while I build my app. It was working on a normal xcode project but while transitioning to app playground it is not working. How can I fix this issue?
0
0
387
Jan ’25
My app stops at 90% on testfight and doesn't download
I am creating an imessage sticker pack and I am having an issue with an update of my app. It publishes to test flight but I can't download it to test. My app has an extension of imessage. I have tried: Checking the size of the animated stickers. All are below 500kb My version number is 4.1.1. so no 0 I am really no sure what to do. Any suggestions would be appreciated.
0
0
212
Jan ’25
Performance difference between Xcode's "Build for Profiling" and xcodebuild for Release
For normal testing I build an application using Xcode and selecting "Build for Profiling" from the Product menu. For production I do "xcodebuild clean build -configuration Release ......." I notice a big performance difference. In my case the XCode profiling build runs in under a minute, the xcodebuild version takes over 4 minutes. The XCode profiling build uses the Release configuration, the xcodebuild is also using the Release configuration. What additional configuration options are being set/used when "Building for Profiling"? I'm having a hard time finding an answer to this question.
2
0
1.2k
Jan ’25
No drop in NSView
Since dragImage: is deprecated I am trying to update drag and drop with beginDraggingSessionWithItems:. Drag work fine but I cannot get drop to work correctly. In the code below change #ifndef to #ifdef (using dragImage:) make drop work as expected. draggingEntered, draggingUpdated, draggingExited, draggingEnded are all called but NOT performDragOperation (which do the drop). Uncommenting the line [pb_item pasteboard:paste_board provideDataForType:@"LN_PboardType"]; cause an exceptionPreprocess: -[NSPasteboardItem pasteboard:provideDataForType:]: unrecognized selector sent to instance 0x600001e64240. I also try add NSDraggingDestination, NSItemProviderWriting, NSPasteboardTypeOwner to @interface line without success. What I am doing wrong ? Any other method to do Drag and Drop (other than dragImage: and beginDraggingSessionWithItems:) ? Where can I found an Obj-C project using beginDraggingSessionWithItems: for drag an drop ? ``@interface Enclosure : NSView <NSDraggingSource, NSPasteboardItemDataProvider> - (id)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) { [super setAutoresizesSubviews:YES]; [self registerForDraggedTypes:[NSArray arrayWithObjects:@"LN_PboardType", NSPasteboardTypeString, nil]]; } return self; } - (BOOL)acceptsFirstMouse:(NSEvent *)event { return YES; } - (void)mouseDown:(NSEvent *)drag_event { NSImage *drag_image; NSPoint drag_position; NSRect dragging_rect; NSPasteboard *paste_board; NSDraggingItem *drag_item; NSArray *items_array; NSPasteboardItem *pb_item; paste_board = [NSPasteboard pasteboardWithName:@"LN_PboardType"]; [paste_board declareTypes:[NSArray arrayWithObjects:@"LN_PboardType", NSPasteboardTypeString, nil] owner:self]; pb_item = [[NSPasteboardItem alloc] init]; [pb_item setDataProvider:self forTypes:[NSArray arrayWithObjects:@"LN_PboardType", NSPasteboardTypeString, nil]]; // [pb_item pasteboard:paste_board provideDataForType:@"LN_PboardType"]; drag_image = [ [NSImage imageNamed:@"drag.jpg"]; drag_position = [self convertPoint:[drag_event locationInWindow] fromView:nil]; drag_position.x -= drag_image.size.width/2; drag_position.y -= drag_image.size.height/2; #ifndef DEPRECATED [self dragImage:drag_image at:drag_position offset:NSZeroSize event:drag_event pasteboard:paste_board source:self slideBack:YES]; #else drag_item = [[NSDraggingItem alloc] initWithPasteboardWriter:pb_item]; dragging_rect = NSMakeRect(drag_position.x, drag_position.y, drag_image.size.width, drag_image.size.height); [drag_item setDraggingFrame:dragging_rect contents:drag_image]; items_array = [NSArray arrayWithObject:drag_item]; [self beginDraggingSessionWithItems:items_array event:drag_event source:(id)self]; #endif } - (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context { if (disable_drag_and_drop) return NSDragOperationNone; switch (context) { case NSDraggingContextWithinApplication: return NSDragOperationCopy; case NSDraggingContextOutsideApplication: return NSDragOperationMove; } return NSDragOperationNone; } …``
0
0
207
Feb ’25
Debug View Hierarchy not showing AVCaptureVideoPreviewLayer
I have an iOS application view that contains an AVCaptureSession, AVCaptureVideoPreviewLayer (created with the AVCaptureSession), and a UIImageView (in the backend the app takes the output of the AVCaptureSession, runs it through a Semantic Segmentation model, and displays the output in the UIImageView). When I pause the app and run the “Debug View Hierarchy”, it shows the UIImageView, the relevant buttons and labels. However, it does not seem to show AVCaptureVideoPreviewLayer that I have set up in my application. Is there some special set up that needs to be done to be able to view Camera Related features? The following is part of the view code, a component that is used to render the AVCaptureVideoPreviewLayer (not sure if this is enough, please let me know if its not): class CameraViewController: UIViewController { var session: AVCaptureSession? var frameRect: CGRect = CGRect() var rootLayer: CALayer! = nil private var previewLayer: AVCaptureVideoPreviewLayer! = nil init(session: AVCaptureSession) { self.session = session super.init(nibName: nil, bundle: nil) } required init?(coder: NSCoder) { super.init(coder: coder) } override func viewDidLoad() { super.viewDidLoad() setUp(session: session!) } private func setUp(session: AVCaptureSession) { previewLayer = AVCaptureVideoPreviewLayer(session: session) previewLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill previewLayer.frame = self.frameRect DispatchQueue.main.async { [weak self] in self!.view.layer.addSublayer(self!.previewLayer) //self!.view.layer.addSublayer(self!.detectionLayer) } } } struct HostedCameraViewController: UIViewControllerRepresentable{ var session: AVCaptureSession! var frameRect: CGRect func makeUIViewController(context: Context) -> CameraViewController { let viewController = CameraViewController(session: session) viewController.frameRect = frameRect return viewController } func updateUIViewController(_ uiView: CameraViewController, context: Context) { } }
3
0
718
Jan ’25
Linking static libraries openssl to Xcode 15.2 project fails due to link errors
Hello, I used to add openssl static libraries (libssl.a, libcrypto.a) that, I created on Mac, and add them after to my C++ project within XCode. With Xcode 14.2 (and before) all works fine. Switching to Xcode 15.2, tons of link errors rise (ld: Undefined symbols). I tried _ld_classic to force use 'old' linker but no success. Rebuild the static libraries with multiple config param or upgrade to recent openssl library does not help. Any clues what went wrong when linking static libraries with Xcode 15.2 project? Thx.
0
0
175
Jan ’25
NWPathMonitor : Lost connection to the debugger
I tried to monitor the device's network status with Network framework code below. let networkMonitor = NWPathMonitor(requiredInterfaceType: .cellular) networkMonitor.pathUpdateHandler = { [weak self] path in     if path.status == .satisfied {         print("Cellular Satisfied")     } else {         print("Cellular Unsatisfied")     } } When I run the app in my iPhone(iOS 15.5) and turn cellular on/off, iPhone suddenly loses connection with XCode. Lost connection to the debugger on “...'s iPhone”. Domain: IDEDebugSessionErrorDomain Code: 12 Recovery Suggestion: Restore the connection to “...'s iPhone” and run “...” again, or if “...” is still running, you can attach to it by selecting Debug &gt; Attach to Process &gt; .... User Info: {     DVTErrorCreationDateKey = "2022-06-23 02:16:30 +0000";     IDERunOperationFailingWorker = DBGLLDBLauncher; } Analytics Event: com.apple.dt.IDERunOperationWorkerFinished : {     "device_model" = "iPhone13,2";     "device_osBuild" = "15.5 (19F77)";     "device_platform" = "com.apple.platform.iphoneos";     "launchSession_schemeCommand" = Run;     "launchSession_state" = 2;     "launchSession_targetArch" = arm64;     "operation_duration_ms" = 5861;     "operation_errorCode" = 12;     "operation_errorDomain" = IDEDebugSessionErrorDomain;     "operation_errorWorker" = DBGLLDBLauncher;     "operation_name" = IDEiPhoneRunOperationWorkerGroup;     "param_consoleMode" = 0;     "param_debugger_attachToExtensions" = 0;     "param_debugger_attachToXPC" = 1;     "param_debugger_type" = 5;     "param_destination_isProxy" = 0;     "param_destination_platform" = "com.apple.platform.iphoneos";     "param_diag_MainThreadChecker_stopOnIssue" = 0;     "param_diag_MallocStackLogging_enableDuringAttach" = 0;     "param_diag_MallocStackLogging_enableForXPC" = 1;     "param_diag_allowLocationSimulation" = 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" = 0;     "param_launcher_substyle" = 0;     "param_runnable_appExtensionHostRunMode" = 0;     "param_runnable_productType" = "com.apple.product-type.application";     "param_runnable_swiftVersion" = "5.6";     "param_runnable_type" = 2;     "param_testing_launchedForTesting" = 0;     "param_testing_suppressSimulatorApp" = 0;     "param_testing_usingCLI" = 0;     "sdk_canonicalName" = "iphoneos15.4";     "sdk_osVersion" = "15.4";     "sdk_variant" = iphoneos; } In my opinion, it seems like an error of XCode. Plz let me know if there's any solution. Also, there's a similar issue here : https://developer.apple.com/forums/thread/681459
7
0
1.4k
Feb ’25
Download Container downloads only partial container
In Xcode Version 16.2 (16C5032a) - and previous versions too, the download container in the Devices & Simulators functionality no longer works. It will start downloading the container, however it will also: show NO download progress fail to download the whole container (the downloaded container is missing whole directories, eg. AppData/Library is missing - where my application stores the CoreData db) show no errors This was tested with the XCode version stated above (and previous versions) and with iPhone XR (18.1.1 - MR42CN/A) and with iPad (17.7.2 - MR7F2FD/A). How can I debug this issue / make the Xcode download the whole container? Running on Mac mini 15.1.1 (24B91).
2
0
225
Feb ’25
Microphone is not being detected in Safari on iOS
What I am trying to do is very simple. Environment description: macOS Catalina version 10.15.7 iOS Simulator version 12.3 Target device iPhone 11 (iOS 13.2.2) Open Safari > go to website > mictests.com Result: "Could not find any media devices. It is very likely that your browser does not allow access to these devices." The Simulator does have access to the microphone. I can use Siri just fine. Only Safari cannot access the mic. I'm really stuck here, any ideas are welcome.
1
0
894
Sep ’25
Error When Trying to Switch from ADEP to AdHoc for iOS App Deployment
I have created two different apps using ADEP, and they were working on iPad with iOS 14.6 and 14.7.1. The environments are as follows: Environment: 1.Mac mini (Mac OS X 10.7.5) Xcode 8.3.2 2.iMac (OS X El Capitan 10.11.6) Xcode 7.3 The certificates were exported from the environment in 1 and imported into 2. When I tried to switch from ADEP to AdHoc for app creation, I encountered an error. Specifically, the app worked fine on an iPad running iOS 12.5.7 in environment 1, but on devices with iOS 14.6, 14.7.1, and 17.7, the installation was successful, but when I tried to open the app, the following error message appeared: “XXXXX” needs to be updated To run this app on this version of iOS, the developer needs to update the app. Additionally, in environment 2, I’m unable to archive the app. Is it possible to create a working app by simply switching from ADEP to AdHoc without making any other changes to the environment?
0
0
121
Feb ’25
Is debugging with App Data broken?
Trying to use App Data on Xcode 16.2, and failing I'm running the app with the debugger. When I run the app, I need to do a handful of things, which affects my app's cache files, and UserDefaults. What I'd like to do is store all of these settings, then have them loaded in when the app launches, so I don't need to do same, tedious work of changing settings by hand in the UI. So, I discovered that I can provide an xcappdata directory in the Run options. This seems like exactly what I'm looking for. But I can't seem to get it to work. Like, when the app runs, it looks like none of those settings are brought in. I ran the app on a device, and pulled down the application data, and then put that in the project. And you can see in the screenshot, that the value is set. So, either I'm missing something (which is totally possible) or this feature is broken. Documentation on this is not great, so maybe I'm doing something wrong. If the feature is known to be broken, I'll give up on this. But if it should work, it would be great to get some tips here.
0
0
226
Jan ’25
How to Handle Identically Named Files in Different Folders in Xcode 16
Hello everyone =) I'm working at the moment on a project in Xcode 16 where I need to have multiple files with the exact same name, stored in different folders (for example, separate quest data files). When I compile, Xcode seems to treat these identically named files as duplicates, causing build errors. How can I properly organize (or configure) Xcode so that it recognizes these files as distinct? Any advice or best practices would be greatly appreciated. Thank you! ;)
0
0
244
Dec ’24
How to handle a non-consumable in app purchase when SKPaymentQueue is deprecated
I use the code below for a non-consumable in-app purchase in my apps. Has anybody worked out how to handle this without using any of the deprecated items? SKPaymentQueue - deprecated, SKPayment - deprecated, SKProduct - deprecated, transactionState - deprecated, SKPaymentTransaction - deprecated, finishTransaction - deprecated func paymentQueue(_ queue: SKPaymentQueue, shouldAddStorePayment payment: SKPayment, for product: SKProduct) -> Bool { true } func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { for transaction in transactions { switch transaction.transactionState { case .purchasing: break case .purchased: SKPaymentQueue.default().finishTransaction(transaction) // Hide the restore button navigationItem.setRightBarButton(nil, animated: true) // Set the ProVerion in the Db to true IAPHandler.setProVersionToPurchased() // Also hide the Purchase button UIView.animate(withDuration: 1.0, animations: { [weak self] in self?.purchaseBtn_Outlet.alpha = 0 }) { [weak self] (success) in if self!.theDevice.isOneOf(K.Device_Groups.SE_3_iPhone8) { self?.segControlTop_Constraint.constant = 10 } else if self!.theDevice.isPhone { self?.segControlTop_Constraint.constant = 30 } } case .failed: if let error = transaction.error { let errorDescription = error.localizedDescription print("Transaction failed due to error: \(errorDescription)") } case .restored: SKPaymentQueue.default().finishTransaction(transaction) // Hide the restore button navigationItem.setRightBarButton(nil, animated: true) // Set the ProVerion in the Db to true IAPHandler.setProVersionToPurchased() // Also hide the Purchase button UIView.animate(withDuration: 1.0, animations: { [weak self] in self?.purchaseBtn_Outlet.alpha = 0 }) { [weak self] (success) in if self!.theDevice.isOneOf(K.Device_Groups.SE_3_iPhone8) { self?.segControlTop_Constraint.constant = 10 } else if self!.theDevice.isPhone { self?.segControlTop_Constraint.constant = 30 } } case .deferred: break @unknown default: if let error = transaction.error { let errorDescription = error.localizedDescription print("Transaction failed due to error: \(errorDescription)") } break } } } // Sets the purchase to true in the Db class IAPHandler: NSObject { //Get the ProVersion Status static func isProVersionPurchased() -> Bool { let VC_String = "IAPHandler" var theStatus = false do { let settings = try Database.shared.databaseConnection!.read { db in try My_Settings.fetchOne(db) } let theStatusText = settings?.ProVersion ?? "false" theStatus = theStatusText == "true" ? true : false } catch { print("Getting the ProVersion Status failed! \(VC_String) \(error)") } return theStatus } // Set ProVersion to true. static func setProVersionToPurchased() { let VC_String = "IAPHandler" do { try Database.shared.databaseConnection!.write { db in try db.execute(sql: "UPDATE My_Settings SET ProVersion = :proVersion WHERE Settings_ID = :id", arguments: ["proVersion": "true", "id": 1]) } } catch { print("Update set pro version, failed! \(VC_String)s \(error)") } } }// End of class
1
0
366
Jan ’25
Xcode Git integration destroyed my git local repository
This is using Xcode 16.2 (16C5032a), MacOS 15.2, on MacbookPro 16 M1 Pro. I have two repositories, one for an application and another one for a framework. The repository framework is integrated into the application one as git submodule. I was going to push the submodule to Github using Xcode git integration. It detects some conflicts and ask to pull. I pull. A window appears with some conflicting files (5 or 6). Review them. While reviewing something in Xcode crashed, but as Xcode was still up and running, ignored the crash. Decided to cancel the conflicts window and inspect my local files. Pull again but this time I decided to pull both repos. Review the conflicting changes and decided to cancel again to continue by hand in a terminal. Then, I notice that the project for the submodule is in red and that the "Changes" tab shows a bunch of files with and admiration mark. I go to the submodule folder in Finder and... everything inside the submodule folder was gone, disappeared, lost... everything, even the ".git" folder (only remained a binary folder for a component I use for the framework but is empty). I decided to run a recovery tool. It finds nothing to recover inside that folder, nothing. A lot of files even from years ago but nothing inside that folder? how is that possible? I filled a Feedback assistant issue: FB16307182 Could it be possible that Xcode "moved" everything to another place (I'm desperate so I'm starting to think in absurd explanations) Thanks
1
0
422
Jan ’25