objective-c

Open a terminal window to a specified folder from a Cocoa app

≯℡__Kan透↙ 提交于 2021-02-07 05:51:40
问题 I have seen this thread on how to execute terminal commands from within a Cocoa app. But I want to actually launch Terminal.app to a specified directory. I know that the following does not work: [[NSWorkspace sharedWorkspace] openFile:folderPath withApplication:@"Terminal"]; Terminal tries to actually open the folder as a file. Is this something I have to use AppleScript for? Any ideas? 回答1: You could use AppleScript from Cocoa like this: NSString *s = [NSString stringWithFormat: @"tell

How to efficiently read thousands of small files with GCD

£可爱£侵袭症+ 提交于 2021-02-07 05:41:26
问题 I'd like to read some metadata data (e.x.: EXIF data) from potentially thousands of files as efficiently as possible without impacting the user experience. I'm interested if anyone has any thoughts on how best to go about this using something like regular GCD queues, dispatch_io channels or even another implementation. Option #1: Using regular GCD queues. This one is pretty straightforward I can just use something like the following: for (NSURL *URL in URLS) { dispatch_async(dispatch_get

How to format objective-c block with clang-format?

你离开我真会死。 提交于 2021-02-07 05:33:51
问题 I have the following code, for example: [cardRegistrationVC setCancelBlock:^{ [weakSelf.navigationController popViewControllerAnimated:YES]; }]; When I apply clang-format on it, it turns into: [cardRegistrationVC setCancelBlock:^{ [weakSelf.navigationController popViewControllerAnimated:YES]; }]; As you can see, code inside the block appears on the same line. But I should be always on a new line. How to set up clang-format correct? My following settings file: BasedOnStyle: LLVM

How to determine height of the toolbar in UINavigationController?

杀马特。学长 韩版系。学妹 提交于 2021-02-07 05:27:25
问题 I have a view with a toolbar presented by a UINavigationController. When I am handling UIKeyboardWillShowNotification, I'm scrolling the entire screen upwards by the height of the keyboard. The thing is when the keyboard is shown, the bottom toolbar is not, so I need to scroll the screen upwards by only (keyboard.height - toolbar.height). But how to get the height of the toolbar? Thanks 回答1: You just should check the toolbar frame. self.navigationController.toolbar.frame.size.height Of course

Call a method from AppDelegate - Objective-C

二次信任 提交于 2021-02-07 05:16:32
问题 I was trying to call an existing method of my ViewController.m from AppDelegate.m inside the applicationDidEnterBackground method, so I found this link: Calling UIViewController method from app delegate, which told me to implement this code: In my ViewController.m -(void)viewDidLoad { [super viewDidLoad]; AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; appDelegate.myViewController = self; } In my AppDelegate: @class MyViewController; @interface AppDelegate :

How to synchronously animate a UIView and a CALayer

怎甘沉沦 提交于 2021-02-07 04:46:30
问题 To illustrate this question, I gisted a very small Xcode project on Github (two classes, 11kb download). Have a look at the gist here or use git clone git@gist.github.com:93982af3b65d2151672e.git . Please consider the following scenario. A custom view of mine, called 'container view', contains two little squares. Illustrated in this screenshot: The blue square is a 22x22 pt UIView instance and the red square is a 22x22 pt CALayer instance. For purposes of this question I want the two squares

React Native: How to export a method with a return value?

帅比萌擦擦* 提交于 2021-02-07 04:46:10
问题 What is the best way to export a method with a return value in React Native? I know there is RCT_EXPORT_METHOD , but that only works for methods that are (void) and therefore don't return anything. Preferably I don't need to export the whole class, just a few methods. The other option would be to have a callback, but I would like to avoid that if possible as it bloats up the code too much in my use case. Are there are any other options I might have missed? 回答1: You can also now use promises,

Using system proxy in NSURLSession - unable to get challenge for setting credentials

泪湿孤枕 提交于 2021-02-07 04:28:47
问题 I've got system proxy configuration which include user credentials (name+password), and I'd like to use it with my NSURLSession object to send http messages in macOS or iOS applications. From connectionProxyDictionary documentation, I haven't set this value to get what I need : The default value is NULL, which means that tasks use the default system settings` My http message goes through the server. However, it appears that the packet doesn't have Proxy-Authorization and I get Cache Access

AES CBC Encryption With PKCS7Padding Has Different Results In Java And Objective-C

馋奶兔 提交于 2021-02-07 04:21:10
问题 I have created an application for Android in Java and used Cipher class to encrypt data with AES. Now I wanna take that algorithm into iOS with CommonCrypto class. The code works but has different results. This is the code in Java : public static String Decrypt(String text, String key) throws Exception { Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); byte[] keyBytes = new byte[16]; byte[] b = key.getBytes("UTF-8"); int len = b.length; if (len > keyBytes.length) len = keyBytes

Animating CALayer shadow simultaneously as UITableviewCell height animates

Deadly 提交于 2021-02-07 03:52:22
问题 I have a UITableView that I am attempting to expand and collapse using its beginUpdates and endUpdates methods and have a drop shadow displayed as that's happening. In my custom UITableViewCell, I have a layer which I create a shadow for in layoutSubviews : self.shadowLayer.shadowColor = self.shadowColor.CGColor; self.shadowLayer.shadowOffset = CGSizeMake(self.shadowOffsetWidth, self.shadowOffsetHeight); self.shadowLayer.shadowOpacity = self.shadowOpacity; self.shadowLayer.masksToBounds = NO;