I have the following code:
public var endpoint: String! {
willSet { if newValue == nil { throw ErrorCode.NullValue("endpoint") } }
}
But compiler gives me error: Error is not handled because the enclosing function is not declared 'throws'
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have the following code:
func numberOfRows(in tableView: NSTableView) -> Int {
switch tableView {
case self.stringsTable:
return self.stringsList?.count ?? 0
case self.localeTable:
return self.localeMap.count
default:
print("numberOfRows not handled for \(tableView)")
return 0
}
}
I wonder if there is any (performance) difference between case and ==== operator like below:
func numberOfRows(in tableView: NSTableView) -> Int {
if tableView === self.stringsTable {
}
// ...
}
In C++, I can write 123457890ull to imply it's an unsigned long long integer. Does Swift provide similar language construct?
I don't get any idea why I am getting the following warnings when I tried to upload one of my apps:
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect
Tags:
App Store
App Submission
This question is related to this post (of mine).
It seems default build settings do not include dSYM files needed when uploading embedding app package. But now Xcode issues new warnings about this.
Now the question - how do I tell Xcode to create dSYM files for me, say when I build My.Framework?
I asked AI chatbot which tells me that for release build I need to :
set "Debug Information Format" to DWARF
set "Strip Debug Symbols During Copy" to off
I have item 1 turned on (which I believe is the default). But item 2 is on, maybe that's the reason I do not have dSYM files in final built My.Framework.
Should I turn "Strip Debug Symbols During Copy" off?
I am a little hesitant to ask this question because it's been years, during which I hoped it's just a specific problem of my own computer or Xcode version.
I'm not sure if it's only me alone with this problem.
First time run of any playground project is extremely slow (after I open it); sometimes it just never runs with the build indicator circling forever).
This is true for objc or swift playgrounds, or different machines, different Xcode versions, different OS versions.
Can anyone help?
I target my project to macOS version 10.10. Now I have an NSStackView in IB and I can set its distribution property in the inspector pane. But there is a yellow warning saying that the distribution property is available only on 10.11+.
My question is - will my app crash if it runs on macOS 10.10?
My app has 2 dylibs linked, in build settings run path is set to "@executable_path/../Frameworks" and a copy file rule is also there. The app runs fine for years now (in App Store).
But once I turn on IB_DESIGNABLE for a custom view, IB reports errors like below:
It seems IB tries to load the dylibs from somewhere in Xcode.app.
What should I do in order to get IB_DESIGNABLE to work in IB?
It seem Apple is forcing developers to use new Xcode 14.3 and Ventura. I am having various rudimentary problems with Xcode 14.2.
Today I created a new project and was surprised to find out that there is Info.plist in the project. I have to copy one from an older project.
I am wondering if Xcode 14.3 does the same thing (not creating Info.plist). Or I am quite behind the trend because I had not updated my apps for more than a year.
EDIT:
Why PRODUCT_BUNDLE_IDENTIFIER is invalid?
I submitted a test package and got the following email:
ITMS-90345: Metadata/Info.plist Mismatch - The value for bundle_identifier in the metadata.xml file does not match the value for CFBundleIdentifier in test [net.neolib.test.pkg/Payload/test.app].
I really don't have any idea what's wrong. It's a simple (almost blank) app with nearly no modification (except linked with a dylib).
What is the metadata.xml? I cannot find it in my test project.
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.
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
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?
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?
I have the following code:
let obj: LanguageItem? = LanguageItem(language: "zh-CN")
// Argument type 'LanguageItem?' does not conform to expected type 'CVarArg'
print(String(format:"obj: %@", obj))
struct LanguageItem: Codable
{
var language: String
var name: String?
}
How can I make my class work with String(format:)?