Mix Swift and C++

RSS for tag

Discuss the WWDC23 Session Mix Swift and C++

View Session

Posts under wwdc2023-10172 tag

9 Posts
Sort by:
Post not yet marked as solved
3 Replies
687 Views
Just a quick observation. I find that the NSNotification.Name NEVPNStatusDidChange is not visible when the Swift Compiler setting: C++ and Objective-C Interoperability is set to C++/Objective-C++. Simply switching between C/Objective-C and C++/Objective-C++, a successfully building app is no longer able to build with error: Type 'NSNotification.Name?' has no member 'NEVPNStatusDidChange'. The Swift code being used is: NotificationCenter.default.addObserver(self, selector: #selector(self.updateNetworkStatus(_:)), name: .NEVPNStatusDidChange, object: nil)
Posted Last updated
.
Post not yet marked as solved
3 Replies
455 Views
Hi, I'm getting a linker error: /usr/bin/c++ -o app -g -O0 -Wall -Wpointer-arith -L/opt/local/lib osx.o -lpthread Undefined symbols for architecture x86_64: "_CFRunLoopAddSource", referenced from: osx.o "_CFRunLoopGetCurrent", referenced from: osx.o "_CFRunLoopRemoveSource", referenced from: osx.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [madchat] Error 1 I can't find where in the documentation the name of the library I must include in the linker command. Is there a reference somewhere that details WHICH .lib or .a file a function comes from? Thank you
Posted Last updated
.
Post not yet marked as solved
1 Replies
498 Views
I have an Objective C++ wrapper class called ImageDividerWrapper in which there is a function I want to use in a Swift class called FrameProcessor. Inside the ImageDividerWrapper.h file I made sure to import the bridging header. I also double-checked that the bridging header was referenced and spelled correctly in Project/Build Settings/Swift Compiler. I also deleted derived data, cleaned build folder, etc.. Also imported ImageDividerWrapper.h into my bridging header file: #import "ImageDividerWrapper.h" And in my ImageDividerWrapper header file I include: #import "Vsn3-Bridging-Header.h" Unfortunately, I still continue to get the error: "No such module 'ImageDividerWrapper'" when trying to directly import the Objective C++ class into my Swift file with: import ImageDividerWrapper If anyone who has solved this problem before can point me in the right direction, I would appreciate it so much! Thank you!
Posted Last updated
.
Post not yet marked as solved
0 Replies
350 Views
Here's how I can reproduce the memory leak: On the home page, I press button A, which calls a method in the view model that creates a std::string using std.string as documented here. Then, I press button B on the home page that opens a modal view. Then, instruments detects a leak of 192 bytes, and the stack trace points to the string I created. It doesn't really make sense to me why there would be a memory leak relating to std::string, so I am asking here. Thanks!
Posted
by jinyangz.
Last updated
.
Post not yet marked as solved
0 Replies
1.2k Views
I have a C++ project that produces a lot of libraries that require C++20. I have tried to set the requirement for that in the module.modulemap like so (for example): module cxx_library { requires cplusplus20 header "library.h" link "CXXLibrary" } This seems to be correct per the clang documentation: https://clang.llvm.org/docs/Modules.html#requires-declaration However I cannot figure out how to get cmd+click on the imported module in my sample swift file to work with this. For one, Xcode seems to refuse to even import my module when it requires C++20. How do I tell Xcode that all of my C++/ObjectiveC++ requires C++20? The compiler default is C++14, but it's not clear how to properly change that so that I can import a C++20-enabled clang module into some sample swift projects to try out the new interior features. If I remove the 20 from my requires statement, and just use my code as-is, It always complains in the UI that: Couldn't Generate Swift Representation Error (from SourceKit): "Could not load module: cxx_library (could not build Objective-C module 'cxx_library', unknown type name 'char8_t')" Which is very frustrating. When I compile with CMake, I can just set this: add_executable(E E.swift) target_compile_options(E PRIVATE -cxx-interoperability-mode=default SHELL:-Xcc SHELL:-std=c++20) target_link_libraries(E PRIVATE cxx_library) And swiftc compiles the code with no issue. I have uploaded a minimized version of my code as a fork of a project by compnerd on GitHub here: https://github.com/ADKaster/swift-cmake-examples/tree/main/Interop The project builds just fine with cmake -S Interop -B build -GNinja cmake --build build But by creating an Xcode project from it: cmake -S Interop -B build-xcode -GXcode and then opening build-xcode/P.xcodeproj in Xcode 15 Beta, and trying to cmd-click on import cxx_library in E.swift does not work.
Posted Last updated
.
Post not yet marked as solved
1 Replies
1.6k Views
As the title suggests, I'm planning to use a combination of Swift and C++ in our application. Our app currently supports iOS 11 as the minimum version, but we're planning to update Xcode in the future and elevate our minimum version to iOS 12. With that in mind, can an app with iOS 12 as its minimum target use Swift 5.9? Additionally, is it possible for an app targeting at least iOS 12 to use a mix of Swift and C++?
Posted
by herohjk.
Last updated
.
Post not yet marked as solved
2 Replies
817 Views
I am attempting to create a C++ file called Fish and to display the fish's num in my SwiftUI app. However, I am encountering the errors "expected ';' after top level declarator" and "unknown type name 'class'; did you mean 'Class'?". It appears that Xcode thinks that the file is a C file. How should I address these errors?
Posted
by jinyangz.
Last updated
.
Post marked as solved
2 Replies
636 Views
I'm getting errors like this: <Error> <Code>AccessDenied</Code> <Message>Access Denied</Message> <RequestId>P4P83RVQKMQQJYBV</RequestId> <HostId> q97d69C6z+0JXEZ8vAQg9QZXUbNaH/umTBIy09FZ7EEDOTWLlX9IQzID4uBHv4Nkq3kF/2SMAHk= </HostId> </Error> Here are the links: https://developer.apple.com/documentation/swift/mixingswiftandc++inanxcodeproject https://docs-assets.developer.apple.com/published/305dd41cfdb1/MixingSwiftAndC++InAnXcodeProject.zip
Posted Last updated
.