Post not yet marked as solved
I have one single menu which is shared by 3 table views as context menu. How do I know programatically on which table view user brings up the context menu?I know I could clone the one menu 2 times and assign a unique id for each of them and thus I can distinguish them, but I'd like to keep just one instance around.
Post not yet marked as solved
I have a menu that is set as context menu of several NSTableViews, like below: let appDelegate = NSApp.delegate as! AppDelegate
self.localeTable.menu = appDelegate.selectMenu
self.fileTable.menu = appDelegate.selectMenu
self.stringsTable.menu = appDelegate.selectMenuNow my problem is that in the menu item's event handler, how do I know which NSTableView is current event for?@IBAction func selectMenuItem_select(_ sender: Any)
}
I persist user selected directory URL to UserDefaults and resolve the bookmark on view load:override func viewDidLoad() {
super.viewDidLoad()
if let bookmarkData = Preferences.instance.lastDirBookmark {
do {
var isStale = false
self.lastDirURL = try URL(resolvingBookmarkData: bookmarkData,
options: .withSecurityScope,
relativeTo: nil,
bookmarkDataIsStale: &isStale)
if isStale {
Preferences.instance.lastDirBookmark = try self.createBookmark(self.lastDirURL!)
}
self.directoryTextField.stringValue = self.lastDirURL!.path
} catch {
NSAlert.errorAlert(error, for: self.view.window!)
}
}
}
@IBAction func locate_click(_ sender: Any) {
let openPanel = NSOpenPanel()
openPanel.canChooseDirectories = true
openPanel.canChooseFiles = false
openPanel.allowsMultipleSelection = false
if openPanel.runModal() == .OK {
if let url = openPanel.url {
self.directoryTextField.stringValue = url.path
self.lastDirURL = url
do {
Preferences.instance.lastDirBookmark = try self.createBookmark(url)
parseFiles()
} catch {
NSAlert.errorAlert(error, for: self.view.window!)
}
}
}
}
private func parseFiles() {
if let url = self.lastDirURL {
if url.startAccessingSecurityScopedResource() {
self.startParseFiles()
url.stopAccessingSecurityScopedResource()
}
}
}My app is correctly sandboxed and com.apple.security.files.user-selected.read-write is true.The code works well for the saved path only. If I try to write files to subdirectories, access will be denied. The subdirectories are dynamic in nature, so my questions is - how to solve this problem without saving too many bookmarks?
Since arrays in Swift are value types, there are many situations that I want something like a list (reference typed). So my questions are:Does Swift has such a class?Or is it possible to declare a reference to an array instance?
Post not yet marked as solved
I want to use code to read in XLIFF files, translate the text (by using some HTTP translator service) and write back. Does Cocoa provide any functions to manipulate exported XLIFF files?
I am having a problem with re-loading a specific project. The first open is good via File->Open menu. Then I quit Xcode and restart it. Now the project reloads, but the Project Navigator only shows "PROJECT NAME.xcodeproj" in red without the normal project folders/files tree. All other projects are good. I think this problem started from version 9.2.
Post not yet marked as solved
I'm not familiar with commandline toolset of gcc/llvm. It is so simple but yet not working as expected. I am becoming suspicious about everything - maybe whole macOS is corrupt?The problem is that the command:ar rcu libt.a @responsefiledoes not work; the error is ar: @responsefile: No such file or directory. But responsefile is right there. I tried 'gcc @testfile' and it works. Help!
I only knew xliff export/import last week. I am experimenting with a test project and got a few puzzling questions.1. I created several localizations, say English, zh-Hans and zh-Hant. After that I add new controls to main window. Now when I export to xliff files, I do not see the new strings in xliff files. I have to regenerate strings files and do export to get new strings into xliffs. Am I doing wrong or is this the required procedures?2. I know I can use xbuild to automate generating strings files. But I cannot find any docs on xliff. Is xliff export/import feature only available in IDE?3. Are there any known automating tools for all these tedious work except the translation part?
For MainWindow.xib I have several localized strings files. Now the problem arises over time when I add new content to MainWindow.xi; every time I would have to manually re-generate the base strings file and do a complex process of compare/copy/merge to other localization files. I'd like to know if there are any tools to automate this tedious and error-prone work. Thanks.
Post not yet marked as solved
I am currently using https://itunes.apple.com/lang/app/id123456789 on my personal website for app links (in several languages). Each language tag is hardcoded into code. I wonder if App Store support a language neutral or automatic app URL that respects user browser language. I mean, if user's browser uses English, then ideally the URL display English content; if Spanish, then it displays Spanish content, etc. Is it possible?
Post not yet marked as solved
It seems Xcode always resolve a symbolic link to its real path. For example, I have ~/Build linked to a directory on another volume (partition), when I "Open In Finder" on a project, the path points to the real directory. I'd prefer the shorter way of ~/Build. Is there any option that instructs Xcode not to follow symbolic links?
Post not yet marked as solved
In another thread about NSDate memory leak, I learned that sometimes I need to wrap code inside an @autoreleasepool. But I get more puzzled when I really try to refactor my code.Here is my problem. I have a NSCondition dervived class which implements a convenience method:- (BOOL)wait:(NSTimeInterval)timeToWait
{
NSDate* date = [[NSDate date] dateByAddingTimeInterval:timeToWait];
BOOL f = [self waitUntilDate:date];
return f;
}In some place, I need to poll on something (don't argue with me about disadvantages about polling):- (void)monitor
{
while (YES)
{
[_guard lock];
if(_guard.stop)
{
break;
}
[_guard wait:DEFAULT_POLL_INTERVAL];
[self check_visibility];
[_guard unlock];
}
}Now I'm bewildered about where to put @autoreleasepool, in the outer loop or directly in the wait: method.Thanks for any suggestions.
Post not yet marked as solved
I once asked a question about how to detect memory leaks when app is running. Thanks for someone who points out that Instruments is the right tool for this purpose.Unfortunately by using Instruments, no explicit memory leaks are detected. But I found a very bewildering problem. It seems [NSDate date] leaks 16 bytes memory on each call. I soon constructed a very simple app to verify this:- (void)viewDidLoad {
[super viewDidLoad];
static NSOperationQueue* q;
q = [[NSOperationQueue alloc] init];
[q addOperationWithBlock:^{
while (YES) {
NSDate* date = [NSDate date];
}
}];
}When the simple app runs, in just about 10 seconds, it's memory usage rockets high to more than 1GB. That explains why one of my App Store app eats up memory gradually on daily usage.I think it is a glaring bug because the code is so simple that it leaves no room for coding mistakes. But, I post it here so that this can be confirmed so that I can submit a formal bug report to Apple.EDIT: it seems the bug occurs after I attached to the test app using Instruments and then stops recoding.EDIT: It seems the above simple code does not always reproduce the bug. Please try the follow:// Replace the line NSDate* date = [NSDate date] with following line
NSDateComponents* parts = [BingImageDate getDateParts:[NSDate date] ofCulture:@"en-US"];//BingImageDate.h
#import <Foundation/Foundation.h>
@interface BingImageDate : NSObject
+ (NSDateComponents *)getDateParts:(NSDate *)date ofCulture:(NSString*)culture;
@end//BingImageDate.m
#import "BingImageDate.h"
static NSCalendar* _gregorian;
static NSTimeZone* _TZ_PST;
static NSDictionary* _cultureHourOffset;
@implementation BingImageDate
+ (void)initialize
{
_gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
_gregorian.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
_TZ_PST = [NSTimeZone timeZoneWithAbbreviation:@"PST"];
_cultureHourOffset = @{
@"de-DE": @1500,
@"en-AU": @700,
@"en-CA": @2100,
@"en-GB": @1600,
@"en-NZ": @0,
@"en-US": @0,
@"fr-FR": @1500,
@"hi-IN": @1130,
@"ja-JP": @800,
@"pt-BR": @2000,
@"zh-CN": @900,
};
}
+ (NSDateComponents *)getDateParts:(NSDate *)date ofCulture:(NSString*)culture
{
NSNumber* cultureHourOffset = _cultureHourOffset[culture];
NSDateComponents* parts = [_gregorian componentsInTimeZone:_TZ_PST fromDate:date];
NSInteger hourOffset = parts.hour * 100 + parts.minute;
if (hourOffset < cultureHourOffset.integerValue)
{
NSDate* pivotDate = [_gregorian dateByAddingUnit:NSCalendarUnitDay
value:-1
toDate:parts.date
options:0];
parts = [_gregorian componentsInTimeZone:_TZ_PST fromDate:pivotDate];
}
return parts;
}
@end
I wonder if it is possible to capture app memory usage/leaks while it is running, especially when a released version is running. Thanks.
Post not yet marked as solved
I had two rare customer report about one of my apps that after long time of running, the app eats up about 2GB memory. I'm quite puzzled in that I do not observe this problem for the past 2 years and I have only 2 customer reports on this problem.The only place that I can think of that eats up memory gradually is one of the method of NSURLConnectionDataDelegate:- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[_data appendData:data];
}The data then is stored in an NSMutableDictionary which is then added to a list. After verything is done, the dictionary is removed off list. That should work without problem and I cannot think of any problem that can cause memory leaks.Any suggestions will be appreciated.