How to use -performSelector:withObject:afterDelay in Command Line Tool - objective-c

I'm trying to use this method on an NSObject in a macOS Command Line Tool.
https://developer.apple.com/documentation/objectivec/nsobject/1416176-performselector?language=objc
This works fine in a normal app but when I try to use it in a Command Line Tool nothings happens. I'm keeping my app running by using dispatch_main(). What else do I need to do to have this method working on an NSObject?
int main(int argc, const char * argv[])
{
#autoreleasepool
{
// ...
}
dispatch_main();
return 0;
}

Related

Window list from AXUIElementRef always null on High Sierra

After "upgrading" to macOS High Sierra it seems that some code that used to work does no longer. My goal here is just to list out the windows owned by an application. Here is an example:
#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import <ApplicationServices/ApplicationServices.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
pid_t myPID = 311;
AXUIElementRef appRef = AXUIElementCreateApplication(myPID);
CFArrayRef windowList;
AXUIElementCopyAttributeValue(appRef, kAXWindowsAttribute, (CFTypeRef *)&windowList);
}
return 0;
}
The issue here specifically is that windowList does not get contain anything no matter what I do. I have tried multiple PIDs, building/running both debug and release builds, and running them with sudo as well.
Any ideas?

Xcode 9 beta 6 error "Reference to 'sqlite3_value' is ambiguous"

I got the below compilation error in FMDB/FMDatabase.m:1404:74:
Reference to 'sqlite3_value' is ambiguous
when I test my iOS project with xCode 9 beta 6.
It is working fine in xCode 8.3.2.
My FMDB library version is 2.4.
I have marked font in bold, where I got compilation error in following lines:
void FMDBBlockSQLiteCallBackFunction(sqlite3_context *context, int argc, sqlite3_value **argv); // -Wmissing-prototypes
void FMDBBlockSQLiteCallBackFunction(sqlite3_context *context, int argc, sqlite3_value **argv) {
Please find the following complete function code snippet in which I got error and also I have attache screenshot for the same .
#pragma mark Callback function
void FMDBBlockSQLiteCallBackFunction(sqlite3_context *context, int argc, sqlite3_value **argv); // -Wmissing-prototypes
void FMDBBlockSQLiteCallBackFunction(sqlite3_context *context, int argc, sqlite3_value **argv) {
#if ! __has_feature(objc_arc)
void (^block)(sqlite3_context *context, int argc, sqlite3_value **argv) = (id)sqlite3_user_data(context);
#else
void (^block)(sqlite3_context *context, int argc, sqlite3_value **argv) = (__bridge id)sqlite3_user_data(context);
#endif
if (block) {
block(context, argc, argv);
}
}
I have tried to resolved it but can not found the solution for it.
It would be appreciate if any help I will get.
Thank you
UPDATE: In Xcode 9(Final release), it is working fine.
how about
1. Clean the project
2. Delete everything inside '~/Library/Developer/Xcode/DerivedData/ModuleCache/' (the button inside the organizer window did not work for me)
3. Clean once more
4. Build project

No output in xcode

Hi i`m starting to develop in objective c, but when I try to show a simple message , thereĀ“s no output i only have this class main.m
import
int main(int argc, const char * argv[])
{
#autoreleasepool {
// insert code here...
NSLog(#"%#",#"Hello, World!");
}
return 0;
}
This should be working, is your debugger showing?
Forget it it was the keyboard that was bad configured.

Argument-array without environment variables?

I'm creating a small C-program and would like a char pointer array holding only the arguments the executable was started with.
Currently this code also outputs all environment variables:
int main (int argc, const char * argv[]) {
while(argv) {
NSLog(#"Parameter %s\n", *argv);
argv++;
}
}
Instead of doing the cycle the way you do, use argc. The size of argv array is argc, with the first value argv[0] being how the name of the program being executed.
int main (int argc, const char * argv[]) {
for (int i = 1; i < argc; ++i) {
NSLog(#"Parameter %s\n", argv[i]);
}
}
Your code is also dumping the environment variables because they are supplied as an additional parameter after argv. In fact you are accessing memory out of bounds for argv and it is pure luck this works.
Change while(argv) to while(*argv). That will give you just the arguments.
main() is actually called like this main(int argc, char **argv, char **environ)
What is happening is you are going past argv and into environ. This behavior
is undefined should not be relied on. Your code, as it is, will also keep on going past environ
and won't stop, you'll be printing garbage.
You can, of course, do it the other way:
for(int i = 0; i < argc; i++) {
NSLog(#"Parameter %s\n", argv[i]);
}
argv[0] contains the program name, the rest are the arguments.

how to pass command line argument in Mac Application

I have created a Command line tool application ( Xocde --> New App --> Command line tool) and its running without any problem,
Now i want to run it through terminal and pass some command line argument, something like this
int main(int argc, const char * argv[])
{
std::cout << "got "<<argc<<" arguments";
for ( int i = 0; i<argc;i++){
std::cout << "argument:"<<i<<"= "<<argv[i];
}
//// some other piece of code
}
if i type on the terminal
>open VisiMacXsltConverter --args fdafsdfasf i am getting output
got 1 argumentsargument:0= /Applications/VisiMacXsltConverte
I want to know through command line what is the way to pass the argument
If you use just one - (hyphen) those values will go into a volatile UserDefaults dictionary (will also override other keys for the life of the process).
./program -Param 4
int main(int argc, const char * argv[])
{
#autoreleasepool {
NSLog(#"param = %#", [[NSUserDefaults standardUserDefaults] valueForKey:#"Param"]);
}
return 0;
}
or you can just pass these in how ever you want and use the following which will give you an NSArray of NSStrings.
[[NSProcessInfo processInfo] arguments];
Why you want to run it with open?
I would run it with (if you have it in you $PATH you should omit the './'):
./VisiMacXsltConverter arg1 arg2 arg3 arg4
Hope I have not misunderstood you question.