Swift Packages

RSS for tag

Create reusable code, organize it in a lightweight way, and share it across Xcode projects and with other developers using Swift Packages.

Posts under Swift Packages tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

How swift string is internally managing memory ?
When i create a intance of swift String : Let str = String ("Hello") As swift String are immutable, and when we mutate the value of these like: str = "Hello world ......." // 200 characters Swift should internally allocate new memory and copy the content to that buffer for update . But when i checked the addresses of original and modified str, both are same? Can you help me understand how this allocation and mutation working internally in swift String?
1
0
72
9h
How the input of UITextField is stored ?
When user enters in a textfield, is the input of textfield gets stored in a String ? If yes, then String in swift being immutable, as user keeps on typing does new memory for storing that text gets allocated with each key stroke ? And when we read users input by using delegate method textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) from textfield.text, we get users input in a String. Is it same storage as used by textfield for storing the user input on key stroke or is it some other storage with copy of the user's input in it? Or is UItextfield using a diffrent data structure (buffer) for storing the user input and when we do textfield.text, it gives a copy of data stored in original buffer?
1
0
70
4h
Seeking advice on building a multiplatform PDF viewer app
Hi everyone, I’m planning to develop a cross-platform PDF viewer app for iOS and macOS that will read PDFs from local storage and cloud services (Google Drive, iCloud, WorkDrive, etc.). The app should be read-only and display both the PDF content and its metadata (author, title, creation date, etc.). Key Features: View PDFs: Local and remote (cloud storage integration). Display metadata: Title, author, page count, etc. Cloud integration: Google Drive, iCloud, Zoho WorkDrive, etc. Read-only mode: No editing features, just viewing. Questions: Xcode Template: Should I use the Document App or Generic App template for this? PDF Metadata: Any built-in libraries for extracting PDF metadata in a read-only app? Performance: Any advice or documentation on handling large PDFs or cloud fetching efficiently? Thanks in advance for any advice or resources!
0
0
84
3d
Xcode16 missing dSYM in Firebase
The problem is that when building the application with Debug mode on Xcode 16.1, the dSYM files fail to upload to Crashlytics. It worked in latest Xcode 15 version. The workaround is to disable Debug Dylib Support in the target's Build Settings. However, this causes SwiftUI previews to stop working. Reproducing the issue Set ENABLE_DEBUG_DYLIB=YES for build options Build the application in Xcode 16.1 Firebase SDK Version 11.4.0 Xcode Version 16.1 Installation Method Swift Package Manager Firebase Version 11.5.0 Relevant Log Output warning: (arm64) /Users/dustin/Library/Developer/Xcode/DerivedData/MyAppName-cicejndcecececfe/Build/Products/Debug-iphonesimulator/MyAppName.app/ MyAppName empty dSYM file detected, dSYM was created with an executable with no debug info. The warning seems like is from XCode/lldb compiler rather than Crashlytics (https://lldb.llvm.org/cpp_reference/SymbolFileDWARF_8cpp_source.html line655). This is probably something on Apple side, Crashlytics only consumes dSYM which is generated from Xcode. (ref:https://github.com/firebase/firebase-ios-sdk/issues/14054#issuecomment-2477235548) This is related to: Firebase Issue
0
2
263
1w
Do i need to put any OS Error handling for Unmanaged.passRetain (obj) or Unmanaged.takeRetain (objptr)
In below Swift code , is there any possiblities of failure of Unmanaged.passRetain and Unmanaged.takeRetain calls ? // can below call fail (constructor returns nil due to OS or language error) and do i need to do explicit error handling here? let str = TWSwiftString(pnew) // Increasing RC by 1 // can below call fail (assuming str is valid) and do i need to do explicit error handling for the same ? let ptr:UnsafeMutableRawPointer? = Unmanaged.passRetained(str).toOpaque() // decrease RC by 1 // can below call fail (assuming ptr is valid) ? and do i need to do explicit error handling Unmanaged<TWSwiftString>.fromOpaque(pStringptr).release()
1
0
170
1w
Compression LZMA2 (SWCompression)
Hi everyone, I am trying to compress my data using LZMA2 with the help of CocoaPods. Here are the steps I followed to achieve LZMA2 compression: Added the pod 'SWCompression', '~&gt; 4.8' dependency to my Podfile and installed the pod using the terminal. When I try to compress the data using LZMA2, I am unable to do so because in SWCompression, LZMA2 compression is marked as TBD (To Be Determined). Here is the current status of SWCompression: Deflate BZip2 LZMA/LZMA2 LZ4 Decompression ✅ ✅ ✅ ✅ Compression ✅ ✅ TBD ✅ Zlib GZip XZ ZIP TAR 7-Zip Read ✅ ✅ ✅ ✅ ✅ ✅ Write ✅ ✅ TBD TBD ✅ TBD Since LZMA2 compression is still marked as TBD, is there any other way to achieve LZMA2 compression for my data in SwiftUI?
1
0
131
1w
[cxx-interop] Avoid breaking changes after enabling Swift C++ interoperability in library
Hi all, Background: I am working as a library developer and would like to enable Swift C++ interoperability in our library. Our library supports both CocoaPods and SPM. Question: I would like to know whether it is possible to avoid breaking changes bring to the library users after enabling Swift C++ interoperability. In my experiment, all apps and packages depend on the library needs to enable interoperability in Xcode or package manage tools, otherwise the source code cannot be complied. I am wondering is there any ways to bypass this? For example, is there a way to only enable Swift C++ interoperability only in our libraries?
1
0
158
1w
Multiple dynamic libraries in a package under SPM
We are currently building an app in Swift, reusing an internal C++ backend used in other platforms ( Linux/Windows/Mac ). Current state of the project: App W - ( Swift App ) Package X - Swift Package Y.xcframework - Binary Target (ios-arm64 and ios-arm64-simulator) Z.framework Z - (C++ Backend as a library) Dynamic Library Headers - Library header files Frameworks (Folder) - Required .dylib’s for Z ( libA.dylib (Dependency of Z) [ 58 of them ] libB.dylib (Runtime dependency of python) [ 123 of them ] data - Supporting binary files for Z conf - Supporting configuration files, both text and binary. for Z python - Supporting .py scripts C.py D.py Z.framework ( C++ ) contains 182 Dynamic Libraries. Goal: Validate the app for distribution with the Apple Store validation tool. Learning when trying to solve the problem: A framework can contain only one dynamic library (e.g. .dylib ) A framework cannot have nested frameworks within a Frameworks folder Certain file types within a framework are not treated as resource files (e.g. .py files) Possible solutions Allow to have nested Frameworks in Z.framework. It’s currently not allowed Link 182 dynamic libraries into the project via SPM Problem: Some of the libraries need to dynamically loaded at runtime (related to the python runtime) Making the libraries static adds significantly technical challenges to the Z.framework. Other questions: What’s the best way to achieve this
1
0
131
1w
Crash calling UIHostingController from a Swift Package
Hello team, We recently found a EXC_BAD_ACCESS crash when using UIHostingControllers on a SPM local Package in our application. This is happening from time to time when we run the app on simulators using Debug configurations. Also, this issue is consistent when we run application tests, there is something weird that we found after making a research... If we disable app test target and only keep packages tests, the crash is not happening, but as soon as we re-enable the app test target from the test suite the crash returns. This is the full error message: Thread 1: EXC_BAD_ACCESS (code=1, address=0xbad4017) A bad access to memory terminated the process. Is this s known issue? We've been performing explorations for some days and couldn't find any real solution for this. A basic call on UIHostingController inside of a SPM local Package is enough to make the app crash, nothing custom being done: UIHostingController(rootView: MyView())
2
0
162
2w
Directly operating on memory pointed by UnsafeMutableRawPointer
In my project, i have a Swift class with a class level property of type string. Like this : class TWSwiftString { var pString:String! init(_ pString: String) { self.pString = pString } } I am creating intance of this class and then creating a opaque pointer to this intance. Like this : let str = TWSwiftString("World") // Increasing RC by 1 strptr = Unmanaged.passRetained(str).toOpaque() Now using this opaque pointer i want to modify the value of pString by directly operating on memory. Like this: withUnsafeMutablePointer(to: &strptr.pString) { strPointer in strPointer.pointee = "World" } Although i am able to modify pString like this and print. Lets assume i have a approach to make sure memory remains valid when it is operated on and freeing of memory is also handled somehow . Will this approach work if i have 100s of intance of this string which are being operated in this manner ? What if the size of new value is greater than existing string value ? For this i am thinking of chunk of memory initially and then keep on increasing size of it as bigger string then this chunk comes. Does this approach seems feasible ? Any other problems i can encounter by using this approach ? Chatgpt gave this answer : To directly update the memory of a Swift class’s property, particularly to alter a String property, is generally discouraged due to Swift's memory safety model. However, if we want to access and modify a class property directly, the best practice is to use a property accessor, as manually altering memory could lead to undefined behavior or even crashes. Why Direct Memory Manipulation Is Risky When you attempt to manipulate memory directly, especially with Swift’s memory model, you might alter not only the value but also the memory layout of Swift’s String type, which could break things internally. The Swift compiler may store String differently based on the internal structure, so even if we manage to locate the correct memory address, directly modifying it is unreliable. do you have any opinion around chatgpt resoponse ?
1
0
114
2w
How to Remove OpaqueTypeErasure from SwiftUI
I am using swiftui lately in my iOS mobile app, The Mobile app already has a pipeline that detect any experimental features and throw an error I am using swift 5 and as you all know SwiftUI is using some of OpaqueTypeErasure utility types like "some" I heard that in swift 6 the OpaqueTypeErasure is not experimental anymore But upgrading the app swift version will be a very long process Also changing the pipeline will be a very long and tiring process So i want to know if there is a way to remove OpaqueTypeErasure from SwiftUI and what is the alternatives for bypassing the error that being thrown from the pipeline
3
0
183
2w
Invalid Swift Support Upon Submit to Testflight/AppStore
Hello, i know this topic is here since ever, also in other forums, however this topic i face for a month and cant get pass it, I tried all other suggestions which didnt bring me anywhere. so, project using cmake in order for Qt creator (so c++ base project with enabled swift), however once i run a cmake which generates *.xcodeproj for Xcode, i open it via xcode and can properly build and deploy to device. however when I try to archive and sent to Testflight/AppStore, I get: ITMS-90426: Invalid Swift Support and when I try to followup guides to create it manualy, copying libs from: $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME) plese here note, that ALL guides indicate to use folder "swift", however there are no *.dylib files... they are only in "swift-5.0" folder then I receive an error type: ITMS-90429: Invalid Swift Support - The files libswiftMetal.dylib, libswiftHomeKit.dylib, libswiftsimd.dylib, libswiftCallKit.dylib, libswiftos.dylib, libswiftNetwork.dylib, libswiftMapKit.dylib, libswiftCoreLocation.dylib, libswiftAccelerate.dylib, libswiftCoreGraphics.dylib, libswiftSceneKit.dylib, libswiftCoreData.dylib, libswiftGameplayKit.dylib, libswiftUIKit.dylib, libswiftMetalKit.dylib, libswiftCore.dylib, libswiftFoundation.dylib, libswiftPhotos.dylib, libswiftModelIO.dylib, libswiftWatchKit.dylib, libswiftDarwin.dylib, libswiftARKit.dylib, libswiftAssetsLibrary.dylib, libswiftSpriteKit.dylib, libswiftNaturalLanguage.dylib, libswiftCoreAudio.dylib, libswiftIntents.dylib, libswiftQuartzCore.dylib, libswiftObjectiveC.dylib, libswiftDispatch.dylib, libswiftCoreFoundation.dylib, libswiftCoreMedia.dylib, libswiftVision.dylib, libswiftAVFoundation.dylib, libswiftContacts.dylib, libswiftGLKit.dylib, libswiftSwiftOnoneSupport.dylib, libswiftXCTest.dylib, libswiftMediaPlayer.dylib, libswiftCloudKit.dylib, libswiftCoreImage.dylib aren’t at the expected location /Payload/Filmtoro.app/Frameworks. Move the file to the expected location, rebuild your app using the current public (GM) version of Xcode, and resubmit it. here please also note that actually *.xcarchive does not contain any "Payload" folder, the package contains only two folders "dSYMs" and "Production/Applications/myapp.app" (inside it I can find "Frameworks" folder... this link was also very interested: https://indiestack.com/2017/03/implicit-swift-dependencies/ tho id didnt help a bit :) so what I would like to know, is what actually forces xcode to generate the SwiftSupport folder to the archive... the must be some direct setting inside *.xcodeproj/pbxproj which forces it... or dirrect setting in xcode/Build Settings which if not work I can submit an ticket to investigate. I am sure after a month of trying everything, whatever tip you can point out I already tried, however Please lets try everything again to get bottom of this. Many thanks for any tip
1
0
205
3w
Xcode (Cloud) vs. Playground App
Hej hej tl;dr. I have problems building a Playground App using Xcode Cloud and I created a reference repository to reproduce this. Did anyone try this before and succeeded? Maybe you have a hint about what's going wrong here. Initial Failure I followed the documentation for Building Swift packages and Swift Playgrounds app projects with Xcode Cloud and I have always run into the following error message: ❌ Code Signing Exporting for App Store Distribution failed. Please download the logs artifact for more information Check Logs “Fair game!” I thought, checked out the logs and see this error appearing twice in each of the following steps: Export archive for ad-hoc distribution Export archive for development distribution Export archive for app-store distribution 5.3 Sec. Run command: 'xcodebuild -exportArchive -archivePath /Volumes/workspace/tmp/3546d064-74fa-42d0-8b36-3623e18941be.xcarchive -exportPath /Volumes/workspace/adhocexport -exportOptionsPlist /Volumes/workspace/ci/ad-hoc-exportoptions.plist '-DVTPortalRequest.Endpoint=http://172.16.35.199:8089' -DVTProvisioningIsManaged=YES -IDEDistributionLogDirectory=/Volumes/workspace/tmp/ad-hoc-export-archive-logs -DVTSkipCertificateValidityCheck=YES -DVTServicesLogLevel=3' Error Command exited with non-zero exit-code: 70 Moving forward, I downloaded the logs artifact as suggested earlier. This is IDEDistribution.standard.log: 2024-10-27 11:15:04 +0000 [MT] Starting export with options: {"embedOnDemandResourcesAssetPacksInBundle":true,"teamID":"38R2LLP8AF","stripSwiftSymbols":true,"thinning":"<none>","iCloudContainerEnvironment":"Development","destination":"export","reformatterBundleIdentifier":"hamburg.plus.encore","uploadSymbols":true,"raiseProfileSupportOptionalToRequired":false,"buildNumber":"4","testFlightInternalTestingOnly":false,"manageAppVersionAndBuildNumber":false,"method":"ad-hoc","generateAppStoreInformation":false} This is IDEDistribution.critical.log (actually it's three times this single error, but I'll spare you the repetition): 2024-10-27 11:15:04 +0000 [MT] -[IDEDistributionMethodManager orderedDistributionMethodsForTask:archive:logAspect:]: Error = Error Domain=IDEDistributionMethodManagerErrorDomain Code=2 "Unknown Distribution Error" UserInfo={NSLocalizedDescription=Unknown Distribution Error} And this is an excerpt (of hopefully relevant details) of IDEDistribution.verbose.log (again, this happens three times, only giving the relevant data points here): … 2024-10-27 11:15:04 +0000 [MT] Rejected distribution method <IDEDistributionMethodiOSAdHoc: 0x600001590100> because it doesn't support distributing archive … 2024-10-27 11:15:04 +0000 [MT] Rejected distribution method <IDEDistributionMethodiOSAppStoreValidation: 0x6000015900f0> because it doesn't support distributing archive … 2024-10-27 11:15:04 +0000 [MT] Rejected distribution method <IDEDistributionMethodiOSAppStoreDistribution: 0x600001590120> because it doesn't support distributing archive … 2024-10-27 11:15:04 +0000 [MT] Rejected distribution method <IDEDistributionMethodiOSAdHoc: 0x600001590100> because it doesn't support distributing archive … 2024-10-27 11:15:04 +0000 [MT] Available distribution methods: {( <IDEDistributionMethodSaveBuiltProducts: 0x6000015f8060>, <IDEDistributionMethodExportArchive: 0x6000015f8070> )} Investigate Xcode Archive (*.xcarchive) At this point, I downloaded the Xcode archive from AppStoreConnect and realized that it only contained debug symbols for the app, but not the app itself. > ls -la /Users/herzi/Downloads/….xcarchive/Products total 0 drwxrwxr-x@ 2 herzi staff 64 27 Okt 12:21 . drwxrwxr-x@ 5 herzi staff 160 27 Okt 12:22 .. Notice the absence of the Applications folder that would contain the Application.app bundle. Current Status So I created a clean, sample repository for my integration. Did anyone try this before and succeeded? Maybe you have a hint about what's going wrong here.
1
0
214
2w
Bitbucket Cloud is Breaking Swift Package Manager
Today when I went to add a package via SPM in Xcode 16.0, the "Recently Used Loading..." spinner ran and never stopped. I could not add any packages. The packages I am loading are remote and not from my own repo. I did a "Refresh Account" via the right-click which then shows items in my own hosted repo (for both Bitbucket Cloud and Github), but "Recently Used" just loads forever and there is no way to add a package. I tried all of the usual cache deleting to no positive outcome. I saw that others had to reinstall Xcode which I am loath to do. I wound up executing defaults delete com.apple.dt.Xcode which of course made me lose all of my settings, but that did correct the problem. At least I thought it did. However, after getting everything reset, it stopped working again with the above issue. In short, I found the issue is with Bitbucket Cloud. If I remove this account from Xcode, SPM works as normal. Add it back (all credentials are 100% fine) and I can no longer use SPM. Does anyone know why Bitbucket Cloud is now breaking SPM and more importantly what can be done to have this account but also have a functioning SPM?
1
0
187
3w
Xcode 16 : dyld[4373]: Symbol not found:
I am getting following error from one of the pod frameworks while running the app (Build is a success). dyld[4373]: Symbol not found: __ZN5swift39swift51override_conformsToSwiftProtocolEPKNS_14TargetMetadataINS_9InProcessEEEPKNS_24TargetProtocolDescriptorIS1_EEN7__swift9__runtime4llvm9StringRefEPFPKNS_35TargetProtocolConformanceDescriptorIS1_EES4_S8_SC_E Referenced from: MyApp.app/Frameworks/vendor.framework/ Expected in: MyApp.app/Frameworks/Alamofire.framework/Alamofire Xcode 16
2
1
239
Oct ’24