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

Posts under Xcode tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Cannot download basic app from testflight
Hi, I have made a very simple app (an app that shows "hello world" in a text field). But when I upload it to testflight I cannot download the app on my Iphone. I have the newest version of macOS (15.0.1 macOS Sequoia) and the newest ios version (ios 18.0.1). I have tried to change the name of the app, the change the bundle identifier, tried to change my certificates in the apple developer page, trying to delete testflight, restarting my phone and more. But it doesn't help. I will add that I cannot add external testers to my app in testflight (I also get an issue here). But for some reason I am able add internal testers (but the invitees cannot download the app in testflight) As written above, I just uploaded the most basic app to testflight and I still cannot download it on my phone (I have also tried to invite other testers and still doesn't work on their phone). I have had this issue the last year, and I have tried almost every solution I could find on the apple developer page, the internet and more. It would really help with a solution to this problem. Pls write a solution.
0
0
98
3d
Issue while adding App to Archive
CodeSign /Users/abc007/Library/Developer/Xcode/DerivedData/App-fjztkcxqsstohgfvqdfnedgpwltj/Build/Intermediates.noindex/ArchiveIntermediates/App/InstallationBuildProductsLocation/Applications/App.app (in target 'App' from project 'App') cd /Users/abc007/Documents/WorkSpace/RegulusIT/Release_Oct_2024/UI\ Backup/ios/App Signing Identity: "Apple Development: Yatin Ghat (JS84GYN3O4)" Provisioning Profile: "iOS Team Provisioning Profile: www.rightschool.net" (bdc0759d-b9d0-4470-8e3f-b5b67d3c2586) /usr/bin/codesign --force --sign 82C0E5904219E333688CE627A21522F732446038 --entitlements /Users/abc007/Library/Developer/Xcode/DerivedData/App-fjztkcxqsstohgfvqdfnedgpwltj/Build/Intermediates.noindex/ArchiveIntermediates/App/IntermediateBuildFilesPath/App.build/Release-iphoneos/App.build/App.app.xcent --generate-entitlement-der /Users/abc007/Library/Developer/Xcode/DerivedData/App-fjztkcxqsstohgfvqdfnedgpwltj/Build/Intermediates.noindex/ArchiveIntermediates/App/InstallationBuildProductsLocation/Applications/App.app /Users/abc007/Library/Developer/Xcode/DerivedData/App-fjztkcxqsstohgfvqdfnedgpwltj/Build/Intermediates.noindex/ArchiveIntermediates/App/InstallationBuildProductsLocation/Applications/App.app: errSecInternalComponent Command CodeSign failed with a nonzero exit code
1
0
103
21h
Apple silicon Macs support issue
After building the app for TextFlight, I uploaded it. After that, I initially received the following message via email. "ITMS-90899: Macs with Apple silicon support issue - The app isn‘t compatible with the provided minimum macOS version of 11.0. It can run on macOS 12.0 or later. Please specify an LSMinimumSystemVersion value of 12.0 or later in a new build, or select a compatible version in App Store Connect." So I added "LSMinimumSystemVersion" to info.plist, increased the version, and uploaded it again. Next "ITMS-90863: Macs with Apple silicon support issue - The app links with libraries that aren’t present in macOS: /usr/lib/swift/libswiftCloudKit.dylib @rpath/libswiftCloudKit.dylib" I received an issue email like the above. The app has supported Mac (Designed by iPad) so far. This time, this issue occurs after building in Xcode 16.0 / MacBook OS 14.6.1. The app being built supports at least iOS 14. We cannot uncheck it because we must support "Mac (Designed by iPad)" in the future. This issue did not occur in the initial upload and distribution. It occurred after deleting all files in the ~/Library/Developer/Xcode/DerivedData path and rebuilding the project. Is this an Xcode bug that will be fixed in the next update? Or is there a separate solution?
0
2
886
3d
Cannot install iOS 18 Simulator in Xcode 16 on Sonoma 14.6.1
Attempting to upgrade to Xcode 16 from 15.3. My team is installing the application from the Apple Developer website, and we are able to successfully install the application and run it. The issue occurs when attempting to install the iOS 18 simulator. We continue to get the same error when attempting to install the simulator via: Xcode CLI using the xcodebuild -downloadPlatform iOS command Downloading the dmg file from the Apple Developer website and running xcrun simctl runtime add iOS_18_Simulator_Runtime.dmg The error we continue to get is the following: Downloading iOS 18.0 Simulator (22A3351): Error: Error Domain=DVTDownloadableErrorDomain Code=29 "Registering simulator runtime with CoreSimulator failed." UserInfo={NSLocalizedDescription=Registering simulator runtime with CoreSimulator failed., NSUnderlyingError=0x600002c70930 {Error Domain=com.apple.CoreSimulator.simdiskimaged.SimDiskImageError Code=10 "Mount failed: SUIS premount dissented" UserInfo={NSLocalizedDescription=Mount failed: SUIS premount dissented, NSLocalizedFailureReason=the operation is not appropriate (kDAReturnNotPermitted)}}} We have attempted reinstalling Xcode multiple times, including cleaning out the Developer directory. We made sure there is over 50GB of space available on the disk, to validate it isn't a space issue. We're currently on macOS Sonoma 14.6.1, which looks like it should be compatible, and might look at updating to macOS 15 to see if that corrects the issue.
1
0
108
3d
XCode 16 Canvas Preview Won't Work
I just downloaded XCode 16.0 and an iOS 18.0 simulator. This simulator works well, and I am also able to view my apps on my iPhone due to the 'XcodePreviews" app on my phone. However, the preview canvas refuses to load. Normally, it would just show itself upon opening the file up in XCode, but now every time I open a project it says "preview paused". When I refresh the canvas, it just loads. The build succeeds and I can view it in the simulator, but not the canvas. This also happens when creating an entirely new project. I would attach my canvas diagnostics report but I am unable to upload a file bigger than 244.140625Kb, so that's impossible to do.
5
0
122
1d
Errors with XCode C++ Standard Libraries
So I was searching for answer to this question but nothing really came up. I am building a C++ static library for iOS and I use <vector> from standard library. However when I try to build I get error from within SDK iOS 17.5 char_trait.h as follows: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.5.sdk/usr/include/c++/v1/__string/char_traits.h:290:17 No member named '__constexpr_wmemcmp' in namespace 'std'; did you mean '__constexpr_memchr'? and in constexpr_c_functions.h as follows: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.5.sdk/usr/include/c++/v1/__string/constexpr_c_functions.h:117:3 Static assertion failed due to requirement 'sizeof(const wchar_t) == 1': Calling memchr on non-trivially equality comparable types is unsafe. I've set my c/c++ standards to C17 and C++17 in the build settings. I have no idea what these weird errors are. Could really use some help.
2
0
116
3d
Xcode's default macOS Deployment Target is 11 which causes Testflight submission warning
If a new (iOS) project is created in Xcode then a default set of deployment targets and values gets automatically created and set as follows: If the iPad, Mac, and Apple Vision supported destinations are deleted from the Xcode general section, these deployment targets still remain. If the app is then built using Xcode 16 and uploaded to TestFlight/App Store then the following issue is reported: TMS-90899: Macs with Apple silicon support issue - The app isn‘t compatible with the provided minimum macOS version of 11.0. Why is XCode populating the macOS deployment target with a value that that results in this issue? Why is Xcode even populating all 6 of these targets at all when its for an iOS app and hence 5 of them are redundant? Can the macOS deployment value simply be increased to silence this issue? Or can these that aren't relevant to iOS be deleted (if so how)? TIA
0
0
151
4d
Encryption and Info.plist
"https://appstoreconnect.apple.com/teams/047b121d-ab98-485e-858b-fa528d4af712/apps/6501988991/testflight/macos" -> "macOS Builds -> The following builds are available to test." show this message about Encryption: "Missing Compliance Manage". My Mac OS application don't use any encryption. From "Complying with Encryption Export Regulations" (https://developer.apple.com/documentation/security/complying-with-encryption-export-regulations): "Add the ITSAppUsesNonExemptEncryption key to your app’s Info.plist file with a Boolean value that indicates whether your app uses encryption. Set the value to NO if your app—including any third-party libraries it links against—doesn’t use encryption" But Info.plist no longer in Xcode (Version 15.4). What can I do ?
0
0
92
5d
XCodeBuild (Xcode16) account verification error
Our CI process uses XcodeBuild tools. It used to work very well. The shell code is as follows: step 1 "++++++++++++++++clean++++++++++++++++" xcodebuild clean -workspace ${WORKSPACE_NAME}.xcworkspace \ -scheme ${SCHEME_NAME} \ -configuration ${configuration} step 2 "+++++++++++++++++archive+++++++++++++++++" xcodebuild archive -workspace ${WORKSPACE_NAME}.xcworkspace \ -scheme ${SCHEME_NAME} \ -configuration ${configuration} \ -archivePath ${ARCHIVE_PATH} -allowProvisioningUpdates YES step 3 "+++++++++++++++++ipa+++++++++++++++++" xcodebuild -exportArchive \ -archivePath ${ARCHIVE_PATH} \ -exportPath "${IPA_PATH}" \ -exportOptionsPlist ${EXPORT_METHOD_PLIST_PATH} \ -allowProvisioningUpdates YES However, there is a problem after upgrading Xcode16. When it is executed to the third step, there will be an error in the error account. Even if I delete my developer account, and then log in again, the same error will still be reported. The specific error is as follows: ** ARCHIVE SUCCEEDED ** /var/folders/ch/1mvd9gz11cn8zy9h254qz2600000gn/T/jenkins6531487518988891980.sh: line 194: -allowProvisioningUpdates: command not found +++++++++++++++++ipa+++++++++++++++++ 2024-10-10 18:20:35.630 xcodebuild[58030:2528109] [MT] IDEDistribution: -[IDEDistributionLogging _createLoggingBundleAtPath:]: Created bundle at path "/var/folders/ch/1mvd9gz11cn8zy9h254qz2600000gn/T/xxxxxx_2024-10-10_18-20-35.623.xcdistributionlogs". 2024-10-10 18:20:35.724 xcodebuild[58030:2528191] DVTDeveloperAccountManager: Failed to load credentials for xxxxxxxxxx: Error Domain=DVTDeveloperAccountCredentialsError Code=0 "Invalid credentials in keychain for xxxxxxxxxx, missing Xcode-Username" UserInfo={NSLocalizedDescription=Invalid credentials in keychain for xxxxxxxxxx, missing Xcode-Username} 2024-10-10 18:20:35.733 xcodebuild[58030:2528191] DVTDeveloperAccountManager: Failed to load credentials for F38D3CD7-C794-4F88-93ED-4FDDD8EDF72B: Error Domain=DVTDeveloperAccountCredentialsError Code=0 "Invalid credentials in keychain for F38D3CD7-C794-4F88-93ED-4FDDD8EDF72B, missing Xcode-Username" UserInfo={NSLocalizedDescription=Invalid credentials in keychain for F38D3CD7-C794-4F88-93ED-4FDDD8EDF72B, missing Xcode-Username} 2024-10-10 18:20:35.742 xcodebuild[58030:2528191] DVTDeveloperAccountManager: Failed to load credentials for ***@***.com: Error Domain=DVTDeveloperAccountCredentialsError Code=0 "Invalid credentials in keychain for ***@***.com, missing Xcode-Token" UserInfo={NSLocalizedDescription=Invalid credentials in keychain for ***@***.com, missing Xcode-Token} 2024-10-10 18:20:40.521 xcodebuild[58030:2528195] IDEDistribution: Failed to log in with account "(null)" while checking for an App Store Connect account (Error Domain=DVTServicesAccountBasedSessionErrorDomain Code=0 "Unable to log in with account ''." UserInfo={NSLocalizedFailureReason=Unable to log in with account ''., NSLocalizedRecoverySuggestion=The login details for account '' were rejected., DVTDeveloperAccountErrorAccount=&lt;DVTAppleIDBasedDeveloperAccount: 0x600002d92a80; username=''&gt;, NSUnderlyingError=0x600002758ab0 {Error Domain=DVTPortalServiceErrorDomain Code=1100 "Your session has expired. Please log in." UserInfo={payload={ creationTimestamp = "2024-10-10T10:20:40Z"; httpCode = 200; protocolVersion = QH65B2; requestUrl = "https://developerservices2.apple.com/services/QH65B2/viewDeveloper.action"; responseId = "12827504-3d86-4601-bcf7-efc0dccb0655"; resultCode = 1100; resultString = "Your session has expired. Please log in."; userLocale = "en_US"; userString = "Your session has expired. Please log in."; }, NSLocalizedDescription=Your session has expired. Please log in.}}}) 2024-10-10 18:20:40.760 xcodebuild[58030:2528195] IDEDistribution: Failed to log in with account "(null)" while checking for an App Store Connect account (Error Domain=DVTServicesAccountBasedSessionErrorDomain Code=0 "Unable to log in with account ''." UserInfo={NSLocalizedFailureReason=Unable to log in with account ''., NSLocalizedRecoverySuggestion=The login details for account '' were rejected., DVTDeveloperAccountErrorAccount=&lt;DVTAppleIDBasedDeveloperAccount: 0x600002de7e80; username=''&gt;, NSUnderlyingError=0x6000027842d0 {Error Domain=DVTPortalServiceErrorDomain Code=1100 "Your session has expired. Please log in." UserInfo={payload={ creationTimestamp = "2024-10-10T10:20:40Z"; httpCode = 200; protocolVersion = QH65B2; requestUrl = "https://developerservices2.apple.com/services/QH65B2/viewDeveloper.action"; responseId = "e49c99d0-861c-4d80-9cd7-8430bcdfa6a6"; resultCode = 1100; resultString = "Your session has expired. Please log in."; userLocale = "en_US"; userString = "Your session has expired. Please log in."; }, NSLocalizedDescription=Your session has expired. Please log in.}}}) 2024-10-10 18:20:41.053 xcodebuild[58030:2528195] IDEDistribution: Failed to log in with account "(null)" while checking for an App Store Connect account (Error Domain=DVTServicesAccountBasedSessionErrorDomain Code=0 "Unable to log in with account '***@***.com'." UserInfo={NSLocalizedFailureReason=Unable to log in with account '***@***.com'., NSLocalizedRecoverySuggestion=The login details for account '***@***.com' were rejected., DVTDeveloperAccountErrorAccount=&lt;DVTAppleIDBasedDeveloperAccount: 0x600002de7b80; username='***@***.com'&gt;, NSUnderlyingError=0x6000027a4780 {Error Domain=DVTPortalServiceErrorDomain Code=1100 "Your session has expired. Please log in." UserInfo={payload={ creationTimestamp = "2024-10-10T10:20:41Z"; httpCode = 200; protocolVersion = QH65B2; requestUrl = "https://developerservices2.apple.com/services/QH65B2/viewDeveloper.action"; responseId = "5819c66e-bd35-4af3-ae6a-0e66193fa2bb"; resultCode = 1100; resultString = "Your session has expired. Please log in."; userLocale = "en_US"; userString = "Your session has expired. Please log in."; }, NSLocalizedDescription=Your session has expired. Please log in.}}}) error: exportArchive The operation couldn’t be completed. Unable to log in with account ''. error: exportArchive Provisioning profile "iOS Team Store Provisioning Profile: com.xxxx.xxxxx" doesn't include signing certificate "Apple Distribution: xxxxxxxxxxx". ** EXPORT FAILED ** At the same time, a lot of blank error accounts will appear in Xcode-Settings-ACCOUNT. The screenshots are as follows How should I solve this problem, I look forward to your reply very much
5
0
151
4h
Not getting scroll wheel input
Hi all, I'm new to swift and I've just gotten started by making a simple pong-like game using SpriteKit. I'm trying to use the scroll wheel input to spin an object, however, nothing seems to make this work. From my googling and AI advice the way I've been doing it should, as shown in the snippet below, however debugging suggests the scrollWheel function isn't even being called. #if os(OSX) extension GameScene { override func scrollWheel(with event: NSEvent ) { print("Scroll detected: \(event.scrollingDeltaY)") let scrollDelta = event.scrollingDeltaY self.rotatePaddle(value: scrollDelta) } } #endif I have changed the build targets in Xcode to Mac os, not the designed-for-ipad version of it, and the app does launch and draw sprites correctly as well as detect other mouse or trackpad inputs like mouseDown and rightMouseDown, so it only seems to be this one specific input not working. I've also tried hardware debugging like restarting Xcode and my Mac, but no luck there either. Maybe I've missed something or am doing it completely wrong, so any help would be much appreciated. Thanks heaps
1
0
89
4d
Could not build obective-c module error for Swift Code
Setup: PLATFORM AND VERSION: iOS Development environment: Xcode Version 16.0 (16A242d), macOS 14.6.1 Run-time configuration: iOS 15-18 tried with same error. When building the app despite the fact it's pure Swift code getting error: CaPark.swift file is here: import Foundation class CarPark: Identifiable, Decodable { var carParkId: String var address: String var totalLots: String var lotsAvailable: String? var lotType:String var lat: Double var lng: Double var couponEps: String var agency: String } Issue seems like started after xcode update to version mentioned above. What i've tried: Clean ups Reinstallation of Xcoce Rollback to previous versions of Xcode Start clean project from VCS App is published and multiple versions were uploaded to AppStore, this problem is new and came out of nowhere. Let me know if additional info is required. Thank you!
0
0
59
5d
Submitting in-app purchases
I have got from App Review Team this same feedback during several months: Guideline 2.1 - Performance - App Completeness We are unable to complete the review of your app because one or more of your in-app purchase products have not been submitted for review. Next Steps To resolve this issue, please be sure to take action and submit your in-app purchases and upload a new binary in App Store Connect so we can proceed with our review. I am unable to understand and implement what is meant by the feedback: … take action … What "action" to take? … submit your in-app purchases … How to "submit in-app purchases"? I know how to submit my app but how "submitting in-app purchases”? My app contains no separate in-app purchases but several pathways through the app. The app's code contains three flags that act as signposts on user’s way through the app (Basic, Standard, Premium). The signposts are not extra content and features distributed on the App Store. They are existing parts in the app from the very beginning. They are activated according to the model user chooses (Basic, Standard, Premium) and loads down from the App Store. I try to solve the problem since several months - without success. Links offer no solution. Links say what one can do but not how to do it. What is missing are a couple of lines of code I can adapt and integrate into my app's Objective-C code. Best regards gefa
1
0
119
5d
Use Vision framework to detect a graph in Swift
I would like to offer the functionality that the user aims the camera at a graph (including axes and scales) and the app detects the graph and the app replicates the graph using the image. I have the whole camera setup finished with a AVCaptureSession, VNDetectContoursRequest, VNImageRequestHandler, etc. However, now I get many many results so I guess I will now need to tell the image processing process what I am looking for. i.e. filter the VNContoursObservations. I 'think' I first need to detect two perpendicular lines (the two axes). How do I do that? If I do not see them, I can just ignore that input and wait for the next VNContoursObservation. When I found the axes of the graph, I will need to find the curve (graph) that I need to scan. Any tips on how I can find that curve and turn that curve into a bunch of coordinates? Thanks! Wouter
1
0
165
5d
Installing an older simulator runtime with xcodebuild: invalid option -buildVersion?
I want to install an older simulator runtime with command line using xcodebuild, following instructions from this article: https://developer.apple.com/documentation/xcode/installing-additional-simulator-runtimes As of October 2024, this article provides an example: xcodebuild -downloadPlatform iOS -buildVersion 16.0 -exportPath ./SimulatorRuntimes/ However when I run this command in the terminal, it fails with error: xcodebuild: error: invalid option '-buildVersion' Has this option been removed? What's the correct way to install an arbitrary non-latest simulator runtime with command line? I know I can download the runtime from the website and then import it, or I can use Xcode's GUI for that, but my eventual goal is to automate it with a single shell script. I'm using Xcode 16.0 (16A242d) on macOS Sequoia 15.0.1. Thanks in advance for your help!
1
0
90
5d
Prevent Virtual Keyboard for iOS App run in macOS
I have a (pretty basic) app I have developed which essentially just opens a pre-defined website (via URL) in WebView. It operates nicely in iOS and almost exactly as expected when run on my M1 in macOS with the exception that in macOS it keeps popping up a grey bar which ... after some investigating ... I have determined appears to be the virtual keyboard. Pressing escape clears it however I am trying to find some way of preventing it from coming up in the first place when the app is run in macOS. Is there a (hopefully simple) solution either through code or some app setting for this?
0
0
111
6d
error: type for self cannot be reconstructed: type for typename
Hi, i have met error below when i tried to po one attributes of an instance in my Xcode lldb: error: type for self cannot be reconstructed: type for typename "$xxxxx" was not found (cached) error: Couldn't realize Swift AST type of self. Hint: using `v` to directly inspect variables and fields may still work. Is there anybody met the same error before? I urgently want to know why this happen and how to fix this issue. My macOS Version is Sequoia v15.0.1, Xcode16.0. This problem showed after i upgraded my macOS and Xcode version.
4
6
284
1d
Simple Xcode CLI/Swift project reflects nothing on change
Once I start a new project everything seems fine and the first commit is always successful. Once I change one of the parameters e.g. set TimeInterval = 6 any consequent run would do absolutely nothing, the only thing I can do is switch back to the old value or start a new project with the new values. I'm currently stuck, anything could help, thanks! import Foundation import CoreGraphics // A helper function to move the cursor smoothly from one coordinate to another. func moveCursor(from start: CGPoint, to end: CGPoint, duration: TimeInterval) { let steps = 100 // Number of steps for smoothness let delay = duration / TimeInterval(steps) // Time delay between each step for i in 0...steps { let progress = Double(i) / Double(steps) // Interpolating X and Y coordinates based on progress (linear interpolation) let newX = start.x + CGFloat(progress) * (end.x - start.x) let newY = start.y + CGFloat(progress) * (end.y - start.y) // Move the cursor let point = CGPoint(x: newX, y: newY) moveCursor(to: point) // Sleep for a short time to create a smooth movement usleep(useconds_t(delay * 1_000_000)) // usleep takes microseconds } } // Function to set the cursor position using CGEvent func moveCursor(to point: CGPoint) { let moveEvent = CGEvent(mouseEventSource: nil, mouseType: .mouseMoved, mouseCursorPosition: point, mouseButton: .left) moveEvent?.post(tap: .cghidEventTap) } // Main function to take multiple coordinates and move between them func moveCursorAlongPath(coords: [CGPoint], totalTime: TimeInterval) { guard coords.count > 1 else { return } let segmentTime = totalTime / TimeInterval(coords.count - 1) // Split time between segments for i in 0..<(coords.count - 1) { let start = coords[i] let end = coords[i + 1] moveCursor(from: start, to: end, duration: segmentTime) } } // Example usage: // Coordinates you want to move between let coordinates: [CGPoint] = [CGPoint(x: 100, y: 100), CGPoint(x: 400, y: 400), CGPoint(x: 800, y: 200)] let totalDuration: TimeInterval = 5 // Total duration in seconds // Move the cursor smoothly along the path moveCursorAlongPath(coords: coordinates, totalTime: totalDuration)``` ![]("https://developer.apple.com/forums/content/attachment/4482329e-42fd-423e-9f4c-860558eeef80" "title=Screenshot 2024-10-09 at 09.29.44.png;width=642;height=331")
0
0
48
6d
[iOS 18] Scrolling behavior does not work only when built in Xcode 16
Code that worked well before upgrading to Xcode 16 doesn't work if it builds on Xcode 16. What doesn't work will not scroll when you use ScrollViewReader to scrollTo with View assigned id. The bug is only reproduced on iOS 18 devices, and it works well on IOS 18 devices when built on Xcode 15 version. Attached is the sample code below. import SwiftUI struct RegisterSheetView: View { @State private var keyword = "" @State private var descriptionMessage: String? @State private var sheetHeight: CGFloat = .zero @State private var sheetFirstPageHeight: CGFloat = .zero @State private var sheetSecondPageHeight: CGFloat = .zero @State private var sheetScrollProgress: CGFloat = .zero var body: some View { GeometryReader(content: { geometry in let size = geometry.size ScrollViewReader(content: { proxy in ScrollView(.horizontal) { HStack(alignment: .top, spacing: 0) { FirstPage(size) .id("First") SecondPage(size) .id("Second") } .scrollTargetLayout() } .scrollTargetBehavior(.paging) .scrollIndicators(.hidden) .overlay(alignment: .topTrailing) { Button(action: { if sheetScrollProgress < 1 { // First Page Button Action withAnimation(.snappy) { proxy.scrollTo("Second", anchor: .leading) } } else { // Second Page Button Action print("Register Button Action") } }, label: { Text("continue") .fontWeight(.semibold) .opacity(1 - sheetScrollProgress) .frame(width: 120 + (sheetScrollProgress * 15)) .overlay(content: { Text("regist") .fontWeight(.semibold) .opacity(sheetScrollProgress) }) .padding(.vertical, 12) .foregroundStyle(.white) .background(.linearGradient(colors: [.red, .orange], startPoint: .topLeading, endPoint: .bottomTrailing), in: .capsule) }) .padding(15) .offset(y: sheetHeight - 100) .offset(y: sheetScrollProgress * -90) } }) }) .presentationCornerRadius(30) .presentationDetents(sheetHeight == .zero ? [.medium] : [.height(sheetHeight)]) .onDisappear { keyword = "" } } // First View @ViewBuilder func FirstPage(_ size: CGSize) -> some View { VStack(alignment: .leading, spacing: 12, content: { Text("First Page") .font(.largeTitle.bold()) .lineLimit(2) Text(attributedSubTitle) .font(.callout) .foregroundStyle(.gray) Text("What's the problem") .foregroundStyle(.blue) .font(.system(size: 16, weight: .semibold)) .frame(width: size.width, alignment: .leading) .onTapGesture { print("Tapped") } }) .padding(15) .padding(.horizontal, 10) .padding(.top, 15) .padding(.bottom, 130) .frame(width: size.width, alignment: .leading) .heightChangePreference { height in sheetFirstPageHeight = height sheetHeight = height } } var attributedSubTitle: AttributedString { let string = "It works fine on Xcode 15 but builds on Xcode 16 and doesn't work on iOS 18 devices." var attString = AttributedString(stringLiteral: string) if let xcode16Range = attString.range(of: "Xcode 16") { attString[xcode16Range].foregroundColor = .black attString[xcode16Range].font = .callout.bold() } if let ios18Range = attString.range(of: "iOS 18") { attString[ios18Range].foregroundColor = .black attString[ios18Range].font = .callout.bold() } return attString } // Second View @ViewBuilder func SecondPage(_ size: CGSize) -> some View { VStack(alignment: .leading, spacing: 12) { Text("Key Registration") .font(.largeTitle.bold()) CustomTextField(hint: "Please enter the contents", text: $keyword, icon: "person") .padding(.top, 20) } .padding(15) .padding(.horizontal, 10) .padding(.top, 15) .padding(.bottom, 190) .overlay(alignment: .bottom, content: { VStack(spacing: 15) { Text("Apple **[Developer Forums](https://developer.apple.com/forums/)**") .font(.caption) .tint(.blue) .foregroundStyle(.gray) } .padding(.bottom, 15) .padding(.horizontal, 20) .multilineTextAlignment(.center) .frame(width: size.width) }) .frame(width: size.width) .heightChangePreference { height in sheetSecondPageHeight = height let diff = sheetSecondPageHeight - sheetFirstPageHeight sheetHeight = sheetFirstPageHeight + (diff * sheetScrollProgress) } .minXChangePreference { minX in let diff = sheetSecondPageHeight - sheetFirstPageHeight let truncatedMinX = min(size.width - minX, size.width) guard truncatedMinX > 0 else { return } let progress = truncatedMinX / size.width sheetScrollProgress = progress sheetHeight = sheetFirstPageHeight + (diff * progress) } } } extension View { @ViewBuilder func heightChangePreference(completion: @escaping (CGFloat) -> ()) -> some View { self .overlay { GeometryReader(content: { geometry in Color.clear .preference(key: SizeKey.self, value: geometry.size.height) .onPreferenceChange(SizeKey.self) { value in DispatchQueue.main.async { completion(value) } } }) } } @ViewBuilder func minXChangePreference(completion: @escaping (CGFloat) -> ()) -> some View { self .overlay { GeometryReader(content: { geometry in Color.clear .preference(key: OffsetKey.self, value: geometry.frame(in: .scrollView).minX) .onPreferenceChange(OffsetKey.self) { value in DispatchQueue.main.async { completion(value) } } }) } } } struct SizeKey: PreferenceKey { static var defaultValue: CGFloat = .zero static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = nextValue() } } struct OffsetKey: PreferenceKey { static var defaultValue: CGFloat = .zero static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = nextValue() } } struct CustomTextField: View { var hint: String @Binding var text: String var icon: String var body: some View { VStack(alignment: .leading, spacing: 12) { TextField(hint, text: $text) .padding(.trailing, 28) .padding(.top, 10) Divider() } .overlay(alignment: .trailing) { Image(systemName: icon) .foregroundStyle(.gray) } } } struct ContentView: View { @State private var isPresented: Bool = false var body: some View { Button { isPresented.toggle() } label: { Text("Show Bottom Sheet") .padding() .background(Color.yellow) } .sheet(isPresented: $isPresented) { RegisterSheetView() } } }
2
0
146
5d