Hi i'm wondering how to use BOOL in macro in xCode?
like this:
#define IS_IPHONE5 (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
#ifdef IS_IPHONE5
# define VIEW_HEIGHT_HALF 284
#else
# define VIEW_HEIGHT_HALF 240
#endif
doesn't work..
so only i can code like this?
#define VIEW_HEIGHT_HALF (([[UIScreen mainScreen] bounds].size.height-568)?240:284)
Thanks.
Trying to squash this warning / bug in my code not sure how to approach this error. Everything in the code works so I am unclear as to why its throwing this error.
"Warning: NSTableView may not respond to "_LocationOfColumn
- (void) _locationOfColumn: (int) aColumn
{
SampleListArrayController *arrayController;
arrayController = (SampleListArrayController *) SampleListController;
if(( [ arrayController libraryIsSelected ] ) && ( aColumn == 4 ))
{
return;
}
[ super _locationOfColumn: aColumn ]; <-- Error on this line.
}
Any help or direction is appreciated.
Well as i mentioned in my comments your method does not respond to the tableview. So i would recommend that in spite of using your custom method for detrmining location of column use below NSTableView delegate method which will Sent to the delegate to allow or prohibit the specified column to be dragged to a new location.:-
-(BOOL)tableView:(NSTableView *)tableView
shouldReorderColumn:(NSInteger)columnIndex toColumn:(NSInteger)newColumnIndex
I've created a UIViewController class with a XIB Attached. Without adding anything, the compiler tells me "UNEXEPTED # IN PROGRAM" on the .h file at the #interface line and repeat the same error on the #end line
#import <UIKit/UIKit.h>
#interface iPegasoDatiCorpoCli : UIViewController
-(id)initWithStrings:(NSString *)lblcorpo1 :(NSString *)lblcorpo2 :(NSString *)lblcorpo3 :(NSString *)<nibNameOrNil :(NSBundle *)nibBundleOrNil;
#end
This class is implemented to create a custo cell view and it worked till now. I've created also a new class just like this one but never used it and still gaves me the same error 3 Builds every 5. It's giving me headache
There is typo, extra > symbol in please check:
-(id)initWithStrings:(NSString *)lblcorpo1 :(NSString *)lblcorpo2 :(NSString *)lblcorpo3 :(NSString *)<nibNameOrNil :(NSBundle *)nibBundleOrNil;
----- ^
EDIT:
Why you are passing 6-7 arguments to a method. Wrap them in a class or pass an array of strings.
I'm getting a semantic warning on Xcode 4 :
*Declaration of 'struct sockaddr_in' will not be visible outside of this function*
the struct seems to be declared in netinet/in.h
The warning is getting marked on Reachability.h, its a class that I downloaded from Apple examples.
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
typedef enum {
NotReachable = 0,
ReachableViaWiFi,
ReachableViaWWAN
} NetworkStatus;
#define kReachabilityChangedNotification #"kNetworkReachabilityChangedNotification"
#interface Reachability: NSObject
{
BOOL localWiFiRef;
SCNetworkReachabilityRef reachabilityRef;
}
//reachabilityWithHostName- Use to check the reachability of a particular host name.
+ (Reachability*) reachabilityWithHostName: (NSString*) hostName;
//reachabilityWithAddress- Use to check the reachability of a particular IP address.
+ (Reachability*) reachabilityWithAddress: (const struct sockaddr_in*) hostAddress;
//reachabilityForInternetConnection- checks whether the default route is available.
// Should be used by applications that do not connect to a particular host
+ (Reachability*) reachabilityForInternetConnection;
//reachabilityForLocalWiFi- checks whether a local wifi connection is available.
+ (Reachability*) reachabilityForLocalWiFi;
//Start listening for reachability notifications on the current run loop
- (BOOL) startNotifier;
- (void) stopNotifier;
- (NetworkStatus) currentReachabilityStatus;
//WWAN may be available, but not active until a connection has been established.
//WiFi may require a connection for VPN on Demand.
- (BOOL) connectionRequired;
#end
I don't understand the warning, can someone explain it to me?
Thank you.
Someone filed a bug report against the behavior and got a response from someone here. Essentially, the problem is that you're declaring a new struct (so far as the compiler can tell) in the parameter of the method, so it will not be accessible elsewhere.
There is a quick fix for it. Simply add the following line to Reachability.h:
#import <netinet/in.h>
You're declaring a new struct in a method parameter, as opposed to at file scope.
The warning will go away if you add a forward declaration at the beginning of the file (somewhere before the #interface section).
struct sockaddr_in ;
Doing this instead of #import <netinet/in.h> avoids header file bloat.
(Speaking of reducing header bloat you can cut down header use in Reachability.h by replacing the lines
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
with
#import <SystemConfiguration/SCNetworkReachability.h>
)
Add #import in Reachability.h to get away with this
Xcode's debugger console makes it easy to see any debugging messages my app sends out using NSLog(), but it always sticks a timestamp prefix on them:
2009-08-30 04:54:48.128 MyApp[94652:a0f] some log message
2009-08-30 04:54:50.647 MyApp[94652:a0f] another log message
...
I have no use for this prefix, and it takes up a lot of room. I have a feeling it is hard-coded into Apple's logging system, but just in case there is a solution out there:
Can I have the debugger console show me log messages without the timestamp prefix?
Something like this would be perfect:
some log message
another log message
...
NSLog() is what is doing that, not the debugger console.
The easiest way to avoid it is to not use NSLog at all. You could use fprintf(), but that is a pain in that it doesn't support %# format types.
I generally write a function for this:
void MyLog(NSString *format, ...) {
va_list args;
va_start(args, format);
NSString *formattedString = [[NSString alloc] initWithFormat: format
arguments: args];
va_end(args);
[[NSFileHandle fileHandleWithStandardOutput]
writeData: [formattedString dataUsingEncoding: NSNEXTSTEPStringEncoding]];
}
Obviously, modify it to add a newline or use a shorter prefix, etc...
(Fixed the stray ctrl-b)
Define a macro
#if __has_feature(objc_arc)
#define MDLog(format, ...) CFShow((__bridge CFStringRef)[NSString stringWithFormat:format, ## __VA_ARGS__]);
#else
#define MDLog(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]);
#endif
And use this macro in you code like
NSLog(#"some log message");
MDLog(#"some log message");
Here is the output of console
NSLog->2014-01-28 10:43:17.873 TestApp[452:60b] some log message
MDLog -> some log message
P.S.
If anyone wants Custom Logs which gives you more info like method name / line number etc. can download the open source MLog.h on GitHub.
put in this one line code in your .pch file and you are done
#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
notice the ## part
A way to keep using NSLog in conjunction with bbum's answer is to use a preprocessor macro to redefine NSLog to your own function
#define USECUSTOMLOGS 1
#if USECUSTOMLOGS
#define NSLog MyLog
#endif
This will replace NSLog with MyLog on compile time. Basically you can keep using NSLog everywhere and it will still use your custom format for the console window. You can also change it back to use NSLog at anytime by changing the 1 to a 0.
ARC Version:
void NFLog(NSString *format, ...)
{
va_list args;
va_start(args, format);
NSString *formattedString = [NSString stringWithFormat:format, args];
formattedString = [formattedString stringByAppendingString:#"\n"];
va_end(args);
[[NSFileHandle fileHandleWithStandardOutput] writeData: [formattedString dataUsingEncoding: NSUTF8StringEncoding]];
}
update:
What I am doing is add this code to xxx-Prefix.pch then you can use it anywhere:
#define newLine do { [(NSFileHandle*)[NSFileHandle fileHandleWithStandardOutput] writeData:[#"\n" dataUsingEncoding: NSUTF8StringEncoding]]; } while(0);
#define NFLog(args,...) do { [(NSFileHandle*)[NSFileHandle fileHandleWithStandardOutput] writeData:[[NSString stringWithFormat:args, ##__VA_ARGS__] dataUsingEncoding: NSUTF8StringEncoding]]; } while(0); newLine
and if you want NSLog back:
#define NFLog(args,...) NSLog(args,##__VA_ARGS__)
In the top left corner of the console window there is a pulldown menu that says All Output / Debugger Output / Target Output.
Select Target Output. It worked on my older versions of Xcode, but to be honest with you it doesn't with my current 4.3 version.
I hope this helps you.
JR
This is way more easier than the suggested solutions. Using carelesslyChoosy's solution and adding a little bit more to make it log entries on release builds only you get the macro below. Just add this macro to your header or .pch file. This macro will show log entries when the DEBUG flag is enabled, on release builds you won't see log entries.
#ifdef DEBUG
#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#define Log(x, ...) NSLog(#"%s %d: " x, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define Log(x, ...)
#endif
Clean Log Macro
Here is a macro I've made for this purpose. It works exactly like NSLog but with just your text, no extra info
Macro (paste to your .h)
#define CLog(__string, ...) fprintf(stderr, "\n%s", [([NSString stringWithFormat:__string, ##__VA_ARGS__]) UTF8String])
Example use:
CLog(#"I am %i days and %i years old", 3, 7);
Logs:
I am 3 days and 7 years old