Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mordicaii

macrumors newbie
Original poster
May 2, 2009
3
0
I have been trying to learn to write files in Obj-C on OS X (not iPhone), and I have been getting a Warning (Picture Below)
picture1yrg.png

What does this Warning mean, and how can I fix the issue?

Code - AppGromit.m
Code:
#import "AppGromit.h"

@implementation AppGromit
- (IBAction)writeFile:(id)sender {
    NSString *fileTest;
	fileTest = @"Hello, I am writing a file";
	[statLabel setIntValue:0];
	if (![fileTest writeToFile:"text.txt" atomically:YES encoding:NSUTF8StringEncoding]) {
		[statLabel setValue:@"Written"];
	}else{
		[statLabel setValue:@"Fail"];
	}
}
@end

Code - AppGromit.h
Code:
#import <Cocoa/Cocoa.h>

@interface AppGromit : NSObject {
	IBOutlet NSTextField *statLabel;
}
- (IBAction)writeFile:(id)sender;
@end

Thank You!
 
The method is writeToFile:atomically:encoding:error:. Note the missing error argument. You can just pass NULL if you don't want the error returned.
 
The method is writeToFile:atomically:encoding:error:. Note the missing error argument. You can just pass NULL if you don't want the error returned.

---It tells me the same thing---
EDIT: It worked, thanks, man.
 
OK yeah, the other thing though is for the file path you should be sending an NSString (using @) there instead of a C string. That's why the other warning you probably got about "incompatible pointer type". So the line should be:

Code:
if (![fileTest writeToFile:@"text.txt" atomically:YES encoding:NSUTF8StringEncoding error:NULL]) {
 
Additionally you should use an absolute path, such as @"/Users/me/Desktop/test.txt"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.