I want to expand the first only root node when NSOutlineView is finished loading all data.
How to get notified in code (possibly by some delegate function)?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
I got a few answers from SO, but the tools are too old and they don't even run my macOS (12.6).
Is there any official way to extract an Assets.car file?
The reason I ask this question is that I want to re-use the icons for strings/storyboard files in Xcode packaged Assets.car (if it's legal).
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'
I could not find any standard error classes/enums in docs. For example, I have the following error situations:
Invalid null parameter
Parameter value out of range
Property value (of T!) not set
This may sound strange, but I encounter real world need on this.
private var queryItems_: [URLQueryItem]?
private var queryItems: [URLQueryItem]? {
get {
if queryItems_ == nil {
if !queries.isEmpty {
queryItems_ = queries.map { (key: String, value: String?) in
return URLQueryItem(name: key, value: value)
}
}
}
return queryItems_
}
}
/// Query strings
public private(set) lazy var queries = [String: String?]() {
didSet {
queryItems_ = nil
}
}
The queryItems will be (re)created on get if queries property was changed. What I wish is that I could use queryItems as a simple var property but let me do my logic in its getter. Is this supported already?
I have a simple test project which has a framework bundle (as a target). See attached screenshots.
When I import MyFramework and use classes from the framework, the app compiles fine but got linker errors. It seems Xcode does not automatically link the bundle into the app.
The following code compiles fine in a normal Swift app, but not in the accompanying unit test bundle.
I don't have any idea why.
import Foundation
struct Dummy: NSObject { // Error: Inheritance from non-protocol type 'NSObject'
var name: String?
}
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:)?
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?
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?
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
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?
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
A simple question, but I am not able to find the answer myself.
Note - I tried ProcessInfo.environment but it does not include system env vars.
I am reading "Managing Strings Files Yourself".
Now the question arises in my mind. Is it possible to add new localizations using ibtool (or alike)?
The reason I have this question is that I have a plan to build an app to automate strings localization so that I will be freed from tedious and repetitive work on translation.