I think I can do this by creating a custom view overriding the following 2 methods:
@implementation MyTextField
- (BOOL)becomeFirstResponder {
NSLog(@"%s: %@", __func__, self);
return [super becomeFirstResponder];
//return YES;
}
- (BOOL)resignFirstResponder {
NSLog(@"%s: %@", __func__, self);
return [super resignFirstResponder];
//return YES;
}
@end
But there is a gotcha - I always get successive become/resign. That is when I get becomeFirstResponder, I also get resignFirstResponder immediately. Note - I only have one MyTextField instance on my window.
Is there another safe way to achieve my goal?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
This is the first time I use KVO pattern. The code is quite simple but I could not get it working - the log method never gets run. What's wrong with my code?
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view.window addObserver:self
forKeyPath:@"firstResponder"
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey,id> *)change
context:(void *)context
{
NSLog(@"%@", change);
}
@end
I have an annoying problem with Xcode 14.2. After opening a project, Quick Help pane works normally. But once a debugging session ends, it stops working (showing nothing). Meanwhile ALT+CLICK won't work either (no response).
After closing and re-opening the project Quick Help works again.
Is there any workaround for this nuiance? I already went back to 13.14.1.
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?
I am in peril. Can anyone save me. I am desperate!
I am using Xcode Version 14.2 (14C18) to build my 2 dylibs. I had no problems with older versions of Xcode (one and half a year ago). But it's causing code signing problems and Connect fails my submitted binary package complaining I had wrong entitlement on dylibs.
I contact Apple technical support and I got a reply:
Entitlements are only effective on a main executable. When you sign a shared library with entitlement then, at best, the system ignores them. However, in some cases you can run into mysterious problems like this one.
The key problem is that Xcode is autogenerating entitlement file for my dylibs. I have no entitlement files in my projects, I am sure.
codesign -d --ent - libsqlite3s.dylib
Executable=/Users/USERNAME/Library/Developer/Xcode/DerivedData/libsqlite3s-ahztenmeyvsijneqjzdtifjhljlr/Build/Products/Debug/libsqlite3s.dylib
[Dict]
[Key] com.apple.application-identifier
[Value]
[String] TEAMID.net.neolib.libsqlite3s
How can I turn off this 'useful' feature?
I am in peril. Can anyone save me. I am desperate!
I am using Xcode Version 14.2 (14C18). I created a fresh new library project (plain C/C++) and added the well-known SQLite3.h and SQLite3.c.
When I build debug configuration, Xcode correctly produces dylib. But when I do archive build, the generated xcarchive is almost empty - it does not have expected libsqlite3s.dylib!
I even went back to Xcode 7.2.1 on macOS 10.10. Xcode 7.2.1 can correctly produce archived dylib and I can link the dylib with a test app.
I am extremely frustrated!
Xcode 14.2 is really crap.
I cannot find the Preview function as what I have in previous version. I cannot find this menu item:
I have not upgraded to Ventura yet. Yesterday one of my user (of one of my apps) mentioned that he has no Python environment on Ventura. Is it true?
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.
This is really disgusting. I really hate to say this.
I started Xcode programming many years ago when it's at version 4 (or even 3). It has been fun and pleasure to program in this IDE, with no problem at all. User rating of this app in App Store was 4.5+.
But 2 or 3 years ago, maybe starting from Xcode 11, it started getting too many quirks/gotchas. App Store user rating drops to 3.5+.
With version 14+, user rating drops to 2.9.
The app's key/main features work. But many small bugs/nuisances put developers like me into peril during daily coding work.
Now I almost want to quit Xcode programming, because it is making my life unpleasant.
I remember last time I could download epub book (5.7) of the Swift language from https://www.swift.org. But now I cannot find the link. Where is the link now?
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.
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 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:)?
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?
}