I vaguely remember I came across some classes about file packages. Just cannot recall the exact names. Can anyone help?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
I have the following in my .zshrc:
export MY_LIBRARY_DIR=~/bin
In Xcode I can set header/lib search path using something like $(MY_LIBRARY_DIR)/abc.
This works fine in my daily used user account. But today I found that this technique does not work in a test user account (for testing purpose only).
I even reboot my machine but still can't get it working.
Am I missing something very obvious???
BTW, I am using Xcode 14.2 and 14.3.1.
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 want to read metadata of image files such as copyright, author etc.
I did a web search and the closest thing is CGImageSourceCopyPropertiesAtIndex:
- (void)tableViewSelectionDidChange:(NSNotification *)notif {
NSDictionary* metadata = [[NSDictionary alloc] init];
//get selected item
NSString* rowData = [fileList objectAtIndex:[tblFileList selectedRow]];
//set path to file selected
NSString* filePath = [NSString stringWithFormat:@"%@/%@", objPath, rowData];
//declare a file manager
NSFileManager* fileManager = [[NSFileManager alloc] init];
//check to see if the file exists
if ([fileManager fileExistsAtPath:filePath] == YES) {
//escape all the garbage in the string
NSString *percentEscapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)filePath, NULL, NULL, kCFStringEncodingUTF8);
//convert path to NSURL
NSURL* filePathURL = [[NSURL alloc] initFileURLWithPath:percentEscapedString];
NSError* error;
NSLog(@"%@", [filePathURL checkResourceIsReachableAndReturnError:error]);
//declare a cg source reference
CGImageSourceRef sourceRef;
//set the cg source references to the image by passign its url path
sourceRef = CGImageSourceCreateWithURL((CFURLRef)filePathURL, NULL);
//set a dictionary with the image metadata from the source reference
metadata = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(sourceRef,0,NULL);
NSLog(@"%@", metadata);
[filePathURL release];
} else {
[self showAlert:@"I cannot find this file."];
}
[fileManager release];
}
Is there any better or easy approach than this?
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?
In C++, I can write 123457890ull to imply it's an unsigned long long integer. Does Swift provide similar language construct?
I am aware Swift deliberately hides details (the actual index number) for safety, by introducing this verbose construct.
But I just got curious - is it possible to convert Index back to its underlying number?
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?
I have had this issue for a long time. If I configure any auto layout constraints in TableViewCell, I get extremely weird layout behavior in IB designer; however, layout is completely good during runtime.
For example, with a completely new project and a single NSTableView on the main view, I get:
If I resize main view, the tableview won't get resized
Every time I reopen the project, the tableview would shrink by height.
It seems the shrinked height is doubled every time. For example, in the following screenshot, the gap is 56. Next reopen will double the gap to 112.
Is this a known bug? I would want to file bug report at https://feedbackassistant.apple.com.
I cannot get any clue on the differences between these 2 functions of Array type.
Can anyone explain by examples?
I have the following code:
extension FileHandle {
func readInto(_ buffer: inout [UInt8]) -> Int {
buffer.withUnsafeMutableBytes {
Darwin.read(fileDescriptor, $0.baseAddress, $0.count)
}
}
}
It can compile, but I wonder if this is supported since it's code in an app that is going to be submitted to App Store.
The reason I don't use read(upToCount:) or readData(ofLength:) is that I am reading possibly very large files by small chunks and don't want to let Swift runtime allocate small buffers repeatedly.
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 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?
// The builtin encoding does not support GBK/GB2312
String(data: data, encoding: .GBK)
How do I convert data which is encoded in GBK/GB2312 (or anything else) to a string instance?
I have the following code:
let file = "/path/to/en.lproj/Localizable.strings"
let dec = PropertyListDecoder()
var f: PropertyListSerialization.PropertyListFormat = .openStep
do {
//let data = strings.data(using: .utf8)!
let data = try Data(contentsOf: URL(fileURLWithPath: file))
let list = try dec.decode([String: String].self, from: data, format: &f)
print("foramt:", f.rawValue)
list.forEach { print($0.key, $0.value) }
} catch { print(error) }
It seems PropertyListDecoder can correctly decode .strings file format; detected format is openStep (value is 1). But I am note sure because I couldn't find any docs on PropertyListDecoder about .strings file.
Can anyone confirm this?