Post

Replies

Boosts

Views

Created

Generated xcarchive has no built dylib
I am in peril. Can anyone save me. I am desperate! I am using Xcode Version 14.2 (14C18). I created a fresh new library project (plain C/C++) and added the well-known SQLite3.h and SQLite3.c. When I build debug configuration, Xcode correctly produces dylib. But when I do archive build, the generated xcarchive is almost empty - it does not have expected libsqlite3s.dylib! I even went back to Xcode 7.2.1 on macOS 10.10. Xcode 7.2.1 can correctly produce archived dylib and I can link the dylib with a test app. I am extremely frustrated!
1
0
743
Apr ’23
How to write a wrapper around CFSomeRef
I am testing with FSEventStreamCreate which returns an FSEventStreamRef, but I cannot find an equivalent toll-free class in Cocoa. In order to free-up resources used by this Ref, I need to do following: FSEventStreamStop(stream); FSEventStreamInvalidate(stream); FSEventStreamRelease(stream); That is quite error-prone and tedious. So I want to write a wrapper class, but don't have any idea on when or where to release the Ref. Is it correct to do 'free' in dealloc?
1
0
1k
Apr ’23
Weird: let statement leads to nil
I have not touched Swift code for more than a year. My skills become rusty. I am not sure what stupid errors I made in the following code: extension Bundle { func readResourceFile(_ filename: String) -> String? { if let fileUrl = self.resourceURL?.appendingPathComponent(filename, isDirectory: false) { return try? String(contentsOf: fileUrl) } return nil } } class MyVC { //... @IBAction func testButton_click(_ sender: Any) { Task.init { await self.test1() } } func test1() async { var loaded = false do { let result = try await self.webView.evaluateJavaScript("typeof(jQuery)") loaded = result as? String == "function" } catch { self.statusLabel.stringValue = "error: \(error)" } if (loaded) { await self.runUserScript(self.input.string) return } let scriptFiles = ["jQuery.js", "Scriptlets.js"] var count = 0 for scriptFile in scriptFiles { print("Loading \(scriptFile)") do { if let script = Bundle.main.readResourceFile(scriptFile) { try await self.webView.evaluateJavaScript(script) print("Loaded \(scriptFile)") count += 1 } } catch { self.statusLabel.stringValue = "error: \(error)" } } } The line if let script = Bundle.main.readResourceFile(scriptFile) { succeeds but script still is nil and causes app crash in next line self.webView.evaluateJavaScript(script). Bundle.main.readResourceFile(scriptFile) is working if I run this line elsewhere. EDIT: When I click on the I button in debugging on variable script I get: (String) script = <no location, value may have been optimized out> However, I can print(script) and the output is correct.
2
0
549
Apr ’23
libarclite_macosx not found when building a framework project
Not sure if it's specific to me only. I tried to build a framework project using Xcode 14.3.1 RC but got a strange error: File not found: /Users/USERNAME/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_macosx.a The project was created several years ago and was upgraded all the way to Xcode 14.2. I remember last time I posted a question about getting an empty xcarchive when doing archive build. The remedy is quite simple - setting SKIP_INSTALL to no. I wonder if this problem also has a simple remedy.
1
0
2.4k
May ’23
User voice: Apple geniuses, please pay attention to small details!!!
This is really disgusting. I really hate to say this. I started Xcode programming many years ago when it's at version 4 (or even 3). It has been fun and pleasure to program in this IDE, with no problem at all. User rating of this app in App Store was 4.5+. But 2 or 3 years ago, maybe starting from Xcode 11, it started getting too many quirks/gotchas. App Store user rating drops to 3.5+. With version 14+, user rating drops to 2.9. The app's key/main features work. But many small bugs/nuisances put developers like me into peril during daily coding work. Now I almost want to quit Xcode programming, because it is making my life unpleasant.
1
0
416
May ’23
Not able to reference classes/structs in Swift playground sources
I have to admit that this is strange for me. Though I have been using playgrounds for years, but I only write small pieces of code to test simple ideas, and I never used another source file. Today I want to add a new struct in Sources folder. To my surprise, I am not able to reference the struct in the main playground file. Sources/testlets.swift: struct Dummy { var name: String } MyPlayground: var box = Dummy(name: "abc") // error: /.../MyPlayground.playground:22:11 Cannot find 'Dummy' in scope
2
0
913
Aug ’23
How make SomeClass<T> Decodable?
I am trying to encode/decode JSON data, and I have the following code: struct SomeOrdinaryClass: Decodable { // ... } struct SomeBox<T>: Decodable { var data: T? } But Xcode gives me the following error: myfile.swift:16:8 Type 'SomeBox' does not conform to protocol 'Decodable' Is there anyway to overcome this?
1
0
375
Aug ’23
JSONEncoder with dictionary of objects?
I have a need to wrap several kinds of objects into a dictionary say [String: Any?], but how do I tell that the Any? object is all Encodable? let params: [String: Any?] = ["num": 123, "text": "abc", "obj": encodableobject] JSONEncoder().encode(params) // compiler error because Any? is not Encodable
1
0
718
Aug ’23
Does Swift has a string builder class?
In other languages, I usually have a StringBuilder class that provides the functionality to concatenate strings in an efficient way. // pseudo code let sb = StringBuilder() sb.append("text") sb.appendFormat("name=%@", name) I am aware of @resultBuilder, but does Swift provide a builtin construct?
2
0
2.3k
Aug ’23
String interpolation produces a debug description for an optional value; did you mean to make this explicit?
This makes my head dizzy! Help me out of this peril. How to avoid this with my own class objects? let obj: LanguageItem? = LanguageItem(language: "en") print("object: \(obj)") struct LanguageItem: Codable { var language: String var name: String? } extension LanguageItem: CustomStringConvertible { var description: String { "Lang:\(language) name:\(name ?? "(none)")" } } The print statement still prints "Optional(Lang:en name:(none))". How to get rid the Optional prefix?
2
0
542
Aug ’23