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.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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
I have a NSTableView which shows a list of translated text items. I want to provide a Find Bar for user to filter through the items, like the one I have in Xcode.
Of course I don't want so many features; I only want to let user enter some text.
I have a checkbox button in a table column (of course in a NSTableCellView).
@IBAction func check_click(_ sender: Any) {
// How do I know in which row this event occurred?
// Once I get the row index I get the associated data item so that I can update the checked state.
}
Today I spent one hour to get myself educated on Array type.
I have the following class in one of my app:
class PathNode: Hashable, Comparable, CustomStringConvertible {
var name: String!
var path: String!
var children: [PathNode]?
static func == (lhs: PathNode, rhs: PathNode) -> Bool {
lhs.name == rhs.name
}
static func < (lhs: PathNode, rhs: PathNode) -> Bool {
lhs.name < rhs.name
}
func hash(into hasher: inout Hasher) {
hasher.combine(name)
hasher.combine(children)
}
/// Sort child nodes.
func sort() {
if let children = self.children {
children.sort()
for child in children { child.sort() }
}
}
// other members...
}
The problem is in the sort function. I found out in my outline view the result is not sorted even though I did call sort on the root node.
After about one hour's frustration, I came to realize that I forgot one import fact about the array type in Swift - it's a value type!
I have to adjust sort function to the following code:
/// Sort child nodes.
func sort() {
if self.children != nil {
self.children!.sort()
for child in self.children! { child.sort() }
}
}
That's not an elegant way of writing code! Is there any other way to get a 'reference' to an array in Swift?
Suppose I have the following class:
class Some {
var list = [String]()
}
// In other places, I want to append to the list
someInstance.list.append("new string")
// ...but I do not want to re-assign the list itself:
someInstance.list = [String]()
What is the exact syntax for declaring list?
I am having coding design difficulties with Array in Swift, see this post. So I decided to turn to the old NSMutableArray.
I'd like to know if there are any known problems of this approach. Any pitfalls and known practices?
In other languages, I am able to get current function's name using some kind of so-called reflection API. Does Swift provide similar API?
I am still on Xcode 14.3 and my macOS is version 12.7 (21G816).
Today I am surprised to find out that FileMerge tool won't run when I invoke it from Xcode "Open Developer Tool" menu.
Is there a standalone download for this tool? Or is there any better alternatives to it?
I have a function that computes MD5 hash of a file:
func ComputeMD5(ofFile path: String) -> [UInt8]? {
if let data = try? Data(contentsOf: URL(fileURLWithPath: path)) {
var digest = [UInt8](repeating: 0, count: 16)
data.withUnsafeBytes {
_ = CC_MD5($0.baseAddress, UInt32(data.count), &digest)
}
return digest
}
return nil
}
Now I wonder/worry what happens if the file is very huge. Does the runtime perform disk memory paging?
I have a need to list all known audio/image file types in a planned app.
What I have known so far:
images
.apng
.avi, .avif
.gif
.jpg, .jpeg, .jfif, .pjpeg, .pjp
.png
.svg
.webp
audio
.aif
.cda
.mid, .midi
.mp3
.mpa
.ogg
.wav
.wma
What are the missing ones?
I want to convert byte size strings like "1234kb", "100mb" or "5gb" to their actual number representation. Is there any builtin functions for this purpose?
Per the docs, NSImage.imageTypes returns a list UTI's, something like below:
com.adobe.pdf
com.apple.pict
com.adobe.encapsulated-postscript
public.jpeg
public.png
com.compuserve.gif
com.canon.tif-raw-image
...
What I need is get file extensions of a UTI. For example, public.jpeg picture file may have several file extensions, say .jpg,.jpeg,.jfif.
Does Cocoa provide any API to query for this information?
Does Swift support this? Til now my understanding is that reflection only works with public members. Is it possible to get private/static members of a type?
I vaguely remember I came across some classes about file packages. Just cannot recall the exact names. Can anyone help?