Hello everyone!
I'm currently working on an iOS app developed with Swift that involves connecting to a specific bluetooth device and exchanging data even when the app is terminated or running in the background.
I just want to understand why the CBCenterManager should be Implicitly unwrapped to use it. I have check out couple off apple developer sample project it was set to Implicitly unwrapped. can some one help to understand the reason behind this, also what are possible issues/scenario trigger if we set the centermanager to optional "CBcentermanager?"
Thanks in Advance!
Compiler
RSS for tagDiscuss the various compiler and toolchain technologies used in development.
Posts under Compiler tag
105 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi all,
I'm attempting to generate an XCFramework that must maintain ABI stability. The framework is created from an SPM using the attached script generate-FK.sh.
I does not work. Removing the flag BUILD_LIBRARY_FOR_DISTRIBUTION=YES and adding the flag -allow-internal-distribution to xcodebuild -create-xcframework everything is fine. Despite this resolves the problem, it results in the generated module not being ABI stable. However, when attempting the script approach, it generates the XCFramework but when used it raises an error in arm64-apple-ios-private.swiftinterface with no such file or module as soon as it encounters an import statement for ModuleX reading it.
The package structure is attached as Package.swift and te obtained result XCFramework structure is as follows:
MyLibrary.xcframework
├── Info.plist
├── ios-arm64
│ └── MyLibrary.framework
│ ├── Headers
│ │ ├── ModuleH-Swift.h
│ │ ├── ModuleH.modulemap
│ │ ├── ModuleC-Swift.h
│ │ ├── ModuleC.modulemap
│ │ ├── ModuleA-Swift.h
│ │ ├── ModuleA.modulemap
│ │ ├── MyLibrary-Swift.h
│ │ └── MyLibrary.modulemap
│ ├── Info.plist
│ ├── Modules
│ │ └── MyLibrary.swiftmodule
│ │ ├── arm64-apple-ios.abi.json
│ │ ├── arm64-apple-ios.swiftdoc
│ │ └── arm64-apple-ios.swiftmodule
│ └── MyLibrary
└── ios-arm64_x86_64-simulator
└── MyLibrary.framework
├── Headers
│ ├── ModuleH-Swift.h
│ ├── ModuleH.modulemap
│ ├── ModuleC-Swift.h
│ ├── ModuleC.modulemap
│ ├── ModuleA-Swift.h
│ ├── ModuleA.modulemap
│ ├── MyLibrary-Swift.h
│ └── MyLibrary.modulemap
├── Info.plist
├── Modules
│ └── MyLibrary.swiftmodule
│ ├── arm64-apple-ios-simulator.abi.json
│ ├── arm64-apple-ios-simulator.swiftdoc
│ ├── arm64-apple-ios-simulator.swiftmodule
│ ├── x86_64-apple-ios-simulator.abi.json
│ ├── x86_64-apple-ios-simulator.swiftdoc
│ └── x86_64-apple-ios-simulator.swiftmodule
├── MyLibrary
└── _CodeSignature
└── CodeResources
It's worth mentioning that the library must be compatible with both Objective-C and Swift, and Modules A, C, and H are imported into the MyLibrary module as @_exported modules, that is why I've included the headers and module maps.
What is wrong?
Thank you in advance for your assistance.
Files:
generate-FK.sh
Package.swift
Hello,
I'm working with Mac Book Pro M3 Sonoma 14.4.1 and I have an issue with compilation, sometimes after compilation of the project the symlink files inside Xcode.app are updated, and further compilation will do full recompilation. According to the build log, the issue is pthread.h :
Module.NiagaraEditor.9.cpp: Dependency /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread.h is newer than the last execution of the action: 04/23/2024 14:33:55 vs 04/23/2024 00:20:32
I tried to trace the reason for the symlink update with the fs_usage utility like this: sudo fs_usage -w | grep pthread.h and according to the output the only things that coincide with the file modification time:
13:55:37.157163 lstat64 [ 2] -B918-ED122786C40E.activeSandbox/Root//Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread/pthread.h 0.000034 installd.1747894
13:55:37.159691 link ED122786C40E.activeSandbox/Root//Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/pthread/pthread.h 0.000753 installd.1747894
13:55:37.176355 fsgetpath -ED122786C40E.activeSandbox/Root/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/pthread/pthread.h 0.000039 mds.1764823
13:55:37.176612 fsgetpath activeSandbox/Root/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/pthread/pthread.h 0.000026 mds.1764823
13:55:37.176641 fsgetpath 18-ED122786C40E.activeSandbox/Root/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/pthread/pthread.h 0.000016 mds.1764823
13:55:37.176666 fsgetpath E.activeSandbox/Root/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/pthread/pthread.h 0.000014 mds.1764823
13:55:37.176689 fsgetpath 8-B918-ED122786C40E.activeSandbox/Root/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread/pthread.h 0.000014 mds.1764823
13:55:37.186224 lstat64 [ 2] A13-4108-B918-ED122786C40E.activeSandbox/Root//Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread.h 0.000022 installd.1747894
13:55:37.186717 unlink [ 2] A13-4108-B918-ED122786C40E.activeSandbox/Root//Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/pthread.h 0.000010 installd.1747894
There are link and unlink caused by installd process, which makes me think that it could be related to the system software update, but disabling it did not help.
Hi all,
I'm attempting to generate an XCFramework that must maintain ABI stability. The framework is created from an SPM using the attached script generate-FK.sh.
I does not work. Removing the flag BUILD_LIBRARY_FOR_DISTRIBUTION=YES and adding the flag -allow-internal-distribution to xcodebuild -create-xcframework everything is fine. Despite this resolves the problem, it results in the generated module not being ABI stable. However, when attempting the script approach, it generates the XCFramework but when used it raises an error in arm64-apple-ios-private.swiftinterface with no such file or module as soon as it encounters an import statement for ModuleX reading it.
The package structure is attached as Package.swift and te obtained result XCFramework structure is as follows:
MyLibrary.xcframework
├── Info.plist
├── ios-arm64
│ └── MyLibrary.framework
│ ├── Headers
│ │ ├── ModuleH-Swift.h
│ │ ├── ModuleH.modulemap
│ │ ├── ModuleC-Swift.h
│ │ ├── ModuleC.modulemap
│ │ ├── ModuleA-Swift.h
│ │ ├── ModuleA.modulemap
│ │ ├── MyLibrary-Swift.h
│ │ └── MyLibrary.modulemap
│ ├── Info.plist
│ ├── Modules
│ │ └── MyLibrary.swiftmodule
│ │ ├── arm64-apple-ios.abi.json
│ │ ├── arm64-apple-ios.swiftdoc
│ │ └── arm64-apple-ios.swiftmodule
│ └── MyLibrary
└── ios-arm64_x86_64-simulator
└── MyLibrary.framework
├── Headers
│ ├── ModuleH-Swift.h
│ ├── ModuleH.modulemap
│ ├── ModuleC-Swift.h
│ ├── ModuleC.modulemap
│ ├── ModuleA-Swift.h
│ ├── ModuleA.modulemap
│ ├── MyLibrary-Swift.h
│ └── MyLibrary.modulemap
├── Info.plist
├── Modules
│ └── MyLibrary.swiftmodule
│ ├── arm64-apple-ios-simulator.abi.json
│ ├── arm64-apple-ios-simulator.swiftdoc
│ ├── arm64-apple-ios-simulator.swiftmodule
│ ├── x86_64-apple-ios-simulator.abi.json
│ ├── x86_64-apple-ios-simulator.swiftdoc
│ └── x86_64-apple-ios-simulator.swiftmodule
├── MyLibrary
└── _CodeSignature
└── CodeResources
It's worth mentioning that the library must be compatible with both Objective-C and Swift, and Modules A, C, and H are imported into the MyLibrary module as @_exported modules, that is why I've included the headers and module maps.
What is wrong?
Thank you in advance for your assistance.
help me with this issue ,it happens when running c in vs code I have everything installed code runner ,c extensions mingw 64 ;help me out
I have an app that uses Swift 4.2. I am going to update the Swift Compiler Language to Swift 5.
But I have some confusion after my test.
I was able to run async/await code when using Xcode 15 with the version set to Swift 4.2, and it was okay.
But async/await code was developed in Swift5.5. Why it is okay? Is it related to the Xocde Swift version?
And if I use Swift Compiler version 4.2 to run async/await code,what problems might there be ?
I am having a problem with named captures when build with a Regex Builder.
The following code is a simplistic example of the problem that works using an "ordinary" Regex. but when the same regular regex is created with a Regex Builder, it works when using group numbers, but it raises the following typing problem when using capture names (last lines)
Cannot infer type of closure parameter 'm' without a type annotation
// named captures and use with a Regex string to twiggle every alternate chars
let pat = /(?P<a>.)(?P<b>.)/
"abcdef".replacing(pat,with:{m in "\(m.b)\(m.a)"})
// the same Regex but using a Regex Builder
let a = Reference(Substring.self)
let b = Reference(Substring.self)
let patRB = Regex {
Capture(as: a) {.any}
Capture(as: b) {.any}
}
// OK when using capture group numbers
"abcdef".replacing(patRB,with:{m in "\(m.2)\(m.1)"})
// compile error when using group names
"abcdef".replacing(patRB,with:{m in "\(m.b)\(m.a)"})
The following shows the output strings in a Playground
Any hints on what is wrong or on the correct way to add typing information to the closure.
Thanks
I am trying to create a generic structure in my project and I am facing an issue where I get the error "Type 'any B' cannot conform to 'A'", where protocol B is derived from protocol A.
I don't understand why such a structure is problematic and I would really appreciate any insight or alternative solution for this issue I am having.
Issue:
I have a general base protocol-class pair like the following.
protocol A { }
class AClass<T: A> { }
To give an example of my use case, protocol A can be PresenterLogic where AClass is BaseInteractor.
I have a second protocol-class pair which I want to specialize according to its use case.
protocol B: A { }
class BClass: AClass<B> { } // Here, I get "Type 'any B' cannot conform to 'A'"
For example, protocol B being MyPresenterLogic and class BClass being MyInteractor.
Specific Use-Case:
To give a more specific use case, I am trying to build a VIP structure such as the following.
// Base VIP (Ex: Interactor)
protocol PresenterLogic {
}
class Interactor<PL: PresenterLogic>, BusinessLogic {
var presenter: PL?
}
// VIP for Specific Screen (Ex: Interactor)
protocol MyPresenterLogic: PresenterLogic {
}
class MyInteractor: Interactor<MyPresenterLogic> {
// I don't want to declare a second `myPresenter: MyPresenterLogic` here
}
I don't want to declare another presenter instance in MyInteractor, (such as myPresenter: MyPresenterLogic. I want to be able to use the same presenter instance to be inferred to have the sub-protocol type.
That is why I want to use generic classes, but I am stuck. I am searching if this is supported. Any insight is appreciated. Thank you.
I build an XCFramework in xcode 15.3 and install the framework in my example application.
Everything is fine when I run the example app in xcode 15.3, but if I run the example app in xcode 15.2 I get this error:
Undefined symbol: _swift_FORCE_LOAD$_swiftXPC
Linker command failed with exit code 1 (use -v to see invocation)
I made tests with different versions of XCode and differents versions of XCFramework compilation and only versions compiled in XCode 15.3 has problems
Resume:
App Xcode 15.3 -> Framework 15.3 -> :white_check_mark:
App xcode 15.2 -> Framework 15.3 -> :x:
App xcode 15.1 -> Framework 15.3 -> :x:
App Xcode 15.3 -> Framework 15.2 -> :white_check_mark:
App xcode 15.2 -> Framework 15.2 -> :white_check_mark:
App xcode 15.1 -> Framework 15.2 -> :white_check_mark:
App Xcode 15.3 -> Framework 15.1 -> :white_check_mark:
App xcode 15.2 -> Framework 15.1 -> :white_check_mark:
App xcode 15.1 -> Framework 15.1 -> :white_check_mark:
Could it be a bug on xcode 15.3?
After updating our build server to Xcode 15.3, the frameworks (e.g. CCIeNewsNetworking) we build and release seems to reference SwiftUI.
Our deployment target is iOS11.
Customers have complained when running on iOS12:
dyld: Library not loaded: /System/Library/Frameworks/SwiftUI.framework/SwiftUI
Referenced from: /private/var/containers/Bundle/Application/81538A25-464A-46E0-BC4D-6E1C002C82F0/Test.app/Frameworks/CCIeNewsNetworking.framework/CCIeNewsNetworking
Reason: image not found
and I can see that "import SwiftUI" now appears in arm64-apple-ios.private.swiftinterface:
diff CCIeNewsNetworking.xcframework-7.3*/ios-arm64/CCIeNewsNetworking.framework/Modules/CCIeNewsNetworking.swiftmodule/arm64-apple-ios.private.swiftinterface
2,4c2,3
< // swift-compiler-version: Apple Swift version 5.8.1 (swiftlang-5.8.0.124.5 clang-1403.0.22.11.100)
< // swift-module-flags: -target arm64-apple-ios11.0 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -Onone -module-name CCIeNewsNetworking
< // swift-module-flags-ignorable: -enable-bare-slash-regex
---
> // swift-compiler-version: Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
> // swift-module-flags: -target arm64-apple-ios11.0 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -Onone -enable-bare-slash-regex -module-name CCIeNewsNetworking
7a7
> import DeveloperToolsSupport
9a10
> import SwiftUI
12a14
> import _SwiftConcurrencyShims
217c219
< @objc public func removeOperation(issueIdentifer: Swift.String, fileName: Swift.String)
---
> @objc public func removeOperation(issueIdentifier: Swift.String, fileName: Swift.String)
I don't recall having changed anything in the project settings, so where does "import SwiftUI" come from, and how can I avoid it ?
I encountered a compilation issue when trying to use my SDK built in Xcode 15.3 with Xcode 15.2 for our app. According to Apple, Swift provides ABI Stability from Xcode 12.2 onwards, so we didn't face such issues before.
Attached is the compilation error message for your reference.
SDK is built with 'Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)', while this compiler is 'Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)')
I have this code in a network extension:
private func pathForToken(token: audit_token_t) -> String? {
var tokenCopy = token
let bufferSize = UInt32(4096)
let bytes = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(bufferSize))
let length = proc_pidpath_audittoken(&tokenCopy, bytes, bufferSize)
if length != 0 {
return String(cString: bytes).lowercased()
}
return nil
}
bytes appears to be leaked -- the call stack is pathForToken(token:) to specialized static UnsafeMutablePointer.allocate(capacity:)
Do I need to do something to ensure bytes is released, since it doesn't seem to be happening on its own?
macOS Sonoma 14.4
Xcode 15.3
Hi,
I'm experimenting with C++/Swift interop and am following the official documentation, especially the section "Using Swift APIs of Imported Framework Target".
I'm able to call Swift code from C++ when both Swift and C++ source files belong to the same app bundle or framework target, by importing the -Swift.h header.
However, I'm not able to import the Swift code from a framework using a different C++ target.
This is my test project setup:
testApp is my app bundle and subprocesses is my framework, containing the auto-generated and unchanged subprocesses.h and some example swift code with a single public function. The subprocesses framework is added as a dependency to testApp and the framework has the C++ interoperability enabled.
But when I try to import the auto-generated -Swift.h in main.cpp, it doesn't show up.
What do I need to do so that I can call Swift framework code in a different C++ target? I think I've done everything according to the documentation.
Thanks!
Addendum
I've also experimented with Apple's Xcode example projects. The "Mixing Languages in an Xcode project" (Link) works as expected. I was able to add a command line app target, and when I add the Fibonacci framework as a dependency, I'm able to use #include <Fibonacci/Fibonacci-Swift.h> and access the Swift API.
However, the second of Apple's examples, "Calling APIs Across Language Boundaries" (Link) fails to compile out of the box (No member named 'createForest' in 'ForestBuilder::MagicForest').
Hello
xcode clang: error: "cannot specify -o when generating multiple output files"
I don't think I should after updating Xcode 15.3, where should I check??
I used it well before.
I am developing an app which should run on Ipad, Iphone and Mac. From the app the user shall be able to press a button and copy a result (pure text) into the clipboard so it can be pasted into other apps on the same device (command + V).
This works fairly well on my Ipad (or Iphone) where I use this (IOS) code:
import SwiftUI
import UniformTypeIdentifiers
.....
UIPasteboard.general.setValue(output,
forPasteboardType: UTType.plainText.identifier)
....
The problem is that when I run this on "My Mac (Designed for iPad) - it does not copy the text when run on Mac as compatible iPad app.
I take note that to access the clipboard on MacOS you would need another (MacOS) code like this.
import Cocoa
...
let pasteboard = NSPasteboard.general()
pasteboard.declareTypes([NSPasteboardTypeString], owner: nil)
pasteboard.setString(output, forType: NSPasteboardTypeString)
....
The problem is that Cocoa can only be imported into native MacOS app - and while I recognise this could be handled with a lot of pre-processor statements separating native IOS and native MacOS code - it would highly complicate my code - and I would almost need to write the app twice just switching all the UI's to NS's.
#if os(iOS)
UIPasteboard.general.setValue(output,
forPasteboardType: UTType.plainText.identifier)
#elseif os(macOS)
let pasteboard = NSPasteboard.general()
pasteboard.declareTypes([NSPasteboardTypeString], owner: nil)
pasteboard.setString(output, forType: NSPasteboardTypeString)
#endif
Even for the clipboard example it would start to complicate things. Then add to this that have have several references to other UI-classes which would be NS-classes on a MacOS.
Can this be handled in a smarter way now we actually can run SwiftUI and IOS apps on a Mac????
I know one way could be to copy my output into a text-field from which the user could "Command + C" - but it is really not what I want.
I hope there is something clean and smart for this - so we can assume that IOS apps can actually run on Mac with full compatibility.
Thanks in advance
What would be your recommendations for an online course for learning to use XCODE and planning a swift app ?
After a law degree I've spent 40 years learning systems engineering. Mostly networking, some programming so I have the basics, but there are some absolute mysteries.
My first app was a basic program for the //e a contact database we could save on tape before diks were avai.able. Now I'm stymied with some cryptic messages about not being able to create schema and I simple downloaded the new code and told it to create a new ios app.
My Mac will not run Xcode 15.3 which uses Swift 5.10. It will run Xcode 15.2 which uses Swift 5.9.2. The problem I am seeing is that Apple provides the language guide for Swift 5.10 but not the guide for Swift 5.9. Is this a real problem or am I over reacting, if not, where can I get and how do I install the reference guide for Swift 5.9 that will show up in Xcode
Hello there, I'm struggling with the following issue since Xcode 15 arrived and haven't been able to solve it.
I have a go library c-archive library which I'm using in a iOS app and build were OK until Sonoma updated came last year. I updated all my go libraries and go runtime to latest version and still facing issues:
my make script as follows:
ios-arm64:
CGO_ENABLED=1
GOOS=ios
GOARCH=arm64
SDK=iphoneos
SDK_PATH=xcrun --sdk iphoneos --show-sdk-path
CARCH="arm64"
CC=$(PWD)/clangwrap.sh
CGO_CFLAGS="-fembed-bitcode"
go build -v -buildmode=c-archive -ldflags="-s -w" -gcflags=all="-l -B" -tags ios -o $(IOS_OUT)/btfs.a .
If there is anything else you need I can share more details. Thanks!
Hello, since the latest update of Xcode (Version 15.3 (15E204a)) and Simulator I have the following error message when trying to run my App: "The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions."
My App was running with Simulator and on my iPad without any problems with exactly the same code! A similar version is already running on TestFlight with nearly the same code. What can I do to make my App run again?
Hi. I'm trying to compile simple swift source file with stripping types metadata and names from it. I use these frontend flags:
swiftc -O -Xfrontend -disable-reflection-names -Xfrontend -disable-reflection-metadata -Xfrontend -reflection-metadata-for-debugger-only -Xfrontend -disable-generic-metadata-prespecialization -gnone test.swift
After compiling this test source file I still facing metadata and names in binary after dissembling it with Hopper.
What I'm doing wrong? Please help.