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.
Related
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;
}
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
I was trying to print out the enum constant in Objective-C on Xcode.
The code:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
#autoreleasepool {
enum boolean{
no, yes
};
NSLog(#"%d", yes);
}
return 0;
}
I ran this code and all the console is showing me is "(lldb)".
Is it the syntax that I got wrong?
Or am I missing something here?
Also, I tried it different way using typedef:
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
#autoreleasepool {
typedef enum {
no, yes
} boolean;
boolean boolVal = yes;
NSLog(#"%d", boolVal);
}
return 0;
}
I suspect I did something wrong with printing out the value, with NSLog().
But I have tried using %i, %#, %d. But the output was same, (lldb).
Are there any different ways to print out the enum values?
You have to give the members of the enum values is you want to print them. Try the following.
enum boolean {
no = 0,
yes = 1
};
NSLog(#"yes = %d",yes);
The previous code outputs the following.
yes = 1
Why doesn't the function displayChanged get fired in the following code?
#import <Cocoa/Cocoa.h>
static void displayChanged(CGDirectDisplayID displayID, CGDisplayChangeSummaryFlags flags, void *userInfo) {
NSLog(#"%#, %#", displayID, flags);
}
int main(int argc, const char * argv[])
{
#autoreleasepool {
CGDisplayRegisterReconfigurationCallback(displayChanged, NULL);
CFRunLoopRun();
}
return 0;
}
I'm physically removing (and plugging in) my external display, but the function is never run.
Why?
Just found the solution on this other question
Before calling CFRunLoopRun you have to call NSApplicationLoad to establish a connection with the window server. This is the fixed code for the original question:
#import <Cocoa/Cocoa.h>
static void displayChanged(CGDirectDisplayID displayID, CGDisplayChangeSummaryFlags flags, void *userInfo) {
NSLog(#"%u, %u", displayID, flags);
}
int main(int argc, const char * argv[])
{
#autoreleasepool {
CGDisplayRegisterReconfigurationCallback(displayChanged, NULL);
NSApplicationLoad(); // establish a connection to the window server. In <Cocoa/Cocoa.h>
CFRunLoopRun(); // run the event loop
}
return 0;
}
I couldn't get CGDisplayRegisterReconfigurationCallback to work, so I used distributed notifications instead:
int main(int argc, const char * argv[]) {
#autoreleasepool {
[[NSDistributedNotificationCenter defaultCenter] addObserverForName:#"com.apple.BezelServices.BMDisplayHWReconfiguredEvent" object:nil queue:nil usingBlock:^(NSNotification *notification) {
NSLog(#"Displays changed!");
}];
CFRunLoopRun();
}
return 0;
}
If you're using AppKit (and have a running NSApplication event loop), you can listen for the NSApplicationDidChangeScreenParametersNotification notification. Or, you can implement the -applicationDidChangeScreenParameters: method in your application delegate, which amounts to the same thing.
I am just learning Objective C and I am having great difficulty. This is what is typed and it is giving me an error. I typed the text that is bold. What is wrong with it. It gives me the nested function error right after int main(void)
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [NSAutoreleasePool alloc] init];
// **#include <stdio.h>
int main(void)
int amount = 1000000;
printf("The amount in your account is $%i\n", amount);
return 0;
}**
NSLog(#"Hello, World!");
[pool drain];
return 0;
}
Your problem is that C and it's brethren do not like functions within functions (putting aside gcc extensions for now).
What you seem to be trying to do is to declare a whole new main inside your main. That's a big no-no. What I suspect is that you've cut-and-pasted an entire C program into the middle of your existing main.
Start with:
#import <Foundation/Foundation.h>
#include <stdio.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [NSAutoreleasePool alloc] init];
int amount = 1000000;
printf("The amount in your account is $%i\n", amount);
NSLog(#"Hello, World!");
[pool drain];
return 0;
}
and work your way up from there.