Obj-C parse error - objective-c

I get "! Expected identifier or '('" next to the #import, as well as "Missing context for property implementation" next to the #synthesize directives for the namespace variable onward and the init method.
SoapService.h
#import "SoapDelegate.h"
#interface SoapService : NSObject
{
NSString* _serviceUrl;
NSString* _namespace;
NSString* _username;
NSString* _password;
NSDictionary* _headers;
BOOL _logging;
id<SoapDelegate> _defaultHandler;
}
#property (retain) NSString* serviceUrl;
#property (retain) NSString* namespace;
#property (retain) NSString* username;
#property (retain) NSString* password;
#property (retain) NSDictionary* headers;
#property BOOL logging;
#property (nonatomic, retain) id<SoapDelegate> defaultHandler;
- (id) initWithUrl: (NSString*) url; - (id) initWithUsername: (NSString*) serviceUsername andPassword: (NSString*) servicePassword;
#end
SoapService.m
#import "SoapService.h"
#implementation SoapService
#synthesize serviceUrl = _serviceUrl;
#synthesize namespace = _namespace;
#synthesize logging = _logging;
#synthesize headers = _headers;
#synthesize defaultHandler = _defaultHandler;
#synthesize username = _username;
#synthesize password = _password;
- (id) init {
if ((self = [super init])) {
self.serviceUrl = nil;
self.namespace = nil;
self.logging = NO;
self.headers = nil;
self.defaultHandler = nil;
self.username = nil;
self.password = nil;
}
return self;
}
- (id) initWithUrl: (NSString*) url {
if((self = [self init])) {
self.serviceUrl = url;
}
return self;
}
- (id) initWithUsername: (NSString*) serviceUsername andPassword: (NSString*) servicePassword {
if ((self = [self init])) {
self.username = serviceUsername;
self.password = servicePassword;
}
return self;
}
-(void)dealloc {
[_serviceUrl release];
[_namespace release];
[_username release];
[_password release];
[_headers release];
[_defaultHandler release];
[super dealloc];
}
#end
SoapDelegate.h
#import "SoapFault.h"
#protocol SoapDelegate <NSObject>
- (void) onload: (id) value;
#optional
- (void) onerror: (NSError*) error;
- (void) onfault: (SoapFault*) fault;
#end
I can't see anything wrong! I tried
changing the variable name from
namespace to namespacexx, but no
success.
SoapFault.h
#import "TouchXML.h"
#interface SoapFault : NSObject {
NSString* faultCode;
NSString* faultString;
NSString* faultActor;
NSString* detail;
BOOL hasFault;
}
#property (retain, nonatomic) NSString* faultCode;
#property (retain, nonatomic) NSString* faultString;
#property (retain, nonatomic) NSString* faultActor;
#property (retain, nonatomic) NSString* detail;
#property BOOL hasFault;
+ (SoapFault*) faultWithData: (NSMutableData*) data;
+ (SoapFault*) faultWithXMLDocument: (CXMLDocument*) document;
+ (SoapFault*) faultWithXMLElement: (CXMLNode*) element;
#end
TouchXML.h
#import "CXMLDocument.h"
#import "CXMLElement.h"
#import "CXMLNode.h"
#import "CXMLNode_XPathExtensions.h"
I can go further, but would like to
state that I am compiling with Xcode
4.0.2 and the previous version of the Xcode compiler did NOT raise these
semantic issues. This leads me to
believe that there is some syntax or
notation that has been deprecated.
CXMLDocument.h
#import "CXMLNode.h"
enum {
CXMLDocumentTidyHTML = 1 << 9
};
#class CXMLElement;
#interface CXMLDocument : CXMLNode {
NSMutableSet *nodePool;
}
- (id)initWithXMLString:(NSString *)inString options:(NSUInteger)inOptions error:(NSError **)outError;
- (id)initWithContentsOfURL:(NSURL *)inURL options:(NSUInteger)inOptions error:(NSError **)outError;
- (id)initWithData:(NSData *)inData options:(NSUInteger)inOptions error:(NSError **)outError;
//- (NSString *)characterEncoding;
//- (NSString *)version;
//- (BOOL)isStandalone;
//- (CXMLDocumentContentKind)documentContentKind;
//- (NSString *)MIMEType;
//- (CXMLDTD *)DTD;
- (CXMLElement *)rootElement;
//- (NSData *)XMLData;
//- (NSData *)XMLDataWithOptions:(NSUInteger)options;
//- (id)objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error;
//- (id)objectByApplyingXSLTString:(NSString *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error;
//- (id)objectByApplyingXSLTAtURL:(NSURL *)xsltURL arguments:(NSDictionary *)argument error:(NSError **)error;
//- (id)XMLStringWithOptions:(NSUInteger)options;
#end
CXMLNode.h
#import <Foundation/Foundation.h>
#include <libxml/tree.h>
typedef enum {
CXMLInvalidKind = 0,
CXMLElementKind = XML_ELEMENT_NODE,
CXMLAttributeKind = XML_ATTRIBUTE_NODE,
CXMLTextKind = XML_TEXT_NODE,
CXMLProcessingInstructionKind = XML_PI_NODE,
CXMLCommentKind = XML_COMMENT_NODE,
CXMLNotationDeclarationKind = XML_NOTATION_NODE,
CXMLDTDKind = XML_DTD_NODE,
CXMLElementDeclarationKind = XML_ELEMENT_DECL,
CXMLAttributeDeclarationKind = XML_ATTRIBUTE_DECL,
CXMLEntityDeclarationKind = XML_ENTITY_DECL,
CXMLNamespaceKind = XML_NAMESPACE_DECL,
} CXMLNodeKind;
#class CXMLDocument;
// NSXMLNode
#interface CXMLNode : NSObject {
xmlNodePtr _node;
}
- (CXMLNodeKind)kind;
- (NSString *)name;
- (NSString *)stringValue;
- (NSUInteger)index;
- (NSUInteger)level;
- (CXMLDocument *)rootDocument;
- (CXMLNode *)parent;
- (NSUInteger)childCount;
- (NSArray *)children;
- (CXMLNode *)childAtIndex:(NSUInteger)index;
- (CXMLNode *)previousSibling;
- (CXMLNode *)nextSibling;
//- (CXMLNode *)previousNode;
//- (CXMLNode *)nextNode;
//- (NSString *)XPath;
//- (NSString *)localName;
//- (NSString *)prefix;
//- (NSString *)URI;
//+ (NSString *)localNameForName:(NSString *)name;
//+ (NSString *)prefixForName:(NSString *)name;
//+ (CXMLNode *)predefinedNamespaceForPrefix:(NSString *)name;
- (NSString *)description;
- (NSString *)XMLString;
- (NSString *)XMLStringWithOptions:(NSUInteger)options;
//- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments;
- (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error;
- (NSString*)_XMLStringWithOptions:(NSUInteger)options appendingToString:(NSMutableString*)str;
#end

There's probably something wrong in SoapService.h since the error is showing it near the #import. At compile time, the preprocessor takes the text from this file and puts it at this point. Sometimes a syntax error in the .h isn't figured out until it gets back to the .m. Look near the end of SoapService.h

I think that namespace is a reserved word. Try to change it to something else.

Related

Property not found although it should be

This is a weird bug.
I have this in the header:
#import "UIKit/UIKit.h"
#interface ProxyProfileObject : NSObject <NSCoding> {
NSString *profileName;
NSString *ipAddress;
NSString *port;
}
-(void) setProfileName:(NSString *)string;
-(NSString*) getProfileName;
-(void) setIP:(NSString *)string;
-(NSString*) getIP;
-(void) setPort:(NSString *)string;
-(NSString*) getPort;
#end
And this in the implementation:
#import "ProxyProfileObject.h"
#interface ProxyProfileObject()
#end
#implementation ProxyProfileObject
-(void) setProfileName:(NSString *)string{
profileName = string;
}
-(NSString*) getProfileName{
return profileName;
}
-(void) setIP:(NSString *)string{
ipAddress = string;
}
-(NSString*) getIP{
return ipAddress;
}
-(void) setPort:(NSString *)string{
port = string;
}
-(NSString*) getPort{
return port;
}
// Encoding stuff
- (id)initWithCoder:(NSCoder *)decoder {
if (self = [super init]) {
self.profileName = [decoder decodeObjectForKey:#"profileName"];
self.port = [decoder decodeObjectForKey:#"port"];
self.ipAddress = [decoder decodeObjectForKey:#"ip"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:profileName forKey:#"profileName"];
[encoder encodeObject:ipAddress forKey:#"ip"];
[encoder encodeObject:port forKey:#"port"];
}
#end
I am not sure why it does this. It shouldn't do it as ipAddress is the same thing as port or profile name.
Those are the two files. You can now see by yourself how ipAddress doesn't work.
In your header NSString *ipAddress declares an ivar.
I the implementation self.ipAddress refers to a property.
You declared no such property. Hence the error.
After the edit your problem becomes apparent:
You do not declare a method -(void)setIpAddress:(NSString *)address;
That's what would make Xcode allow you to use property syntax (dot notation) for the setter—even though it's not an actual property.
You are declaring instance variables, not properties. Just put the #property directive in front of the lines.
#interface ProxyProfileObject : NSObject <NSCoding> {}
#property NSString *profileName;
#property NSString *ipAddress;
#property NSString *port;
Edit: Don't write explicit getters and setters. Use the (error-free) synthesized accessors provided by the #property declaration.

Class Not Running

I'm new to Xcode and Objective C, but learning fast. I am writing a Bluetooth LE app to collect data from multiple BLE devices. Happy with CoreBluetooth and am able to get what I want to function and collect the data.
However, I did it all within AppDelegate and now want to separate out different sections of code into neat Classes.
Code compiles okay but nothing runs other than AppDelegate.
Example of the class - SensorDev.m:
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#class SensorDev;
#protocol SensorDevDelegate<NSObject>
- (void) sensorDevDidChangeStatus:(SensorDev*)dev;
#end
#interface SensorDev : NSObject
#property (nonatomic, assign, readonly) id<SensorDevDelegate> delegate;
#property (nonatomic, readonly) CBPeripheral *peripheral;
- (id)initWithPeripheral:(CBPeripheral *)peripheral controller:(id<SensorDevDelegate>)controller;
- (void)start;
#end
Example of the class - SensorDev.h
#import "SensorDev.h"
NSString *SR1Device9DOFServiceUUIDString = #"346D0000";
NSString *SR1Device9DOFCharacteristicUUIDString = #"346D0001-12A9-11CF-1279-81F2B7A91332";
#interface SensorDev() <CBPeripheralDelegate> {
CBService *_temperatureService;
CBCharacteristic *_temperatureCharacteristic;
}
#end
#implementation SensorDev
#pragma mark - Setup
- (id)initWithPeripheral:(CBPeripheral *)peripheral controller:(id<SensorDevDelegate>)controller
{
self = [super init];
if (self) {
_peripheral = peripheral;
_peripheral.delegate = self;
_delegate = controller;
}
return self;
}
#pragma mark - Start
// -------------------------------------------------------------------------------
// Startup
// -------------------------------------------------------------------------------
- (void)start
{
NSLog(#"- (void) start"); //--Debug
CBUUID *serviceUUID = [CBUUID UUIDWithString:SR1Device9DOFServiceUUIDString];
NSArray *serviceArray = [NSArray arrayWithObjects:serviceUUID, nil];
[_peripheral discoverServices:serviceArray];
}
#end
I don't get the debug line in the log:
NSLog(#"- (void) start"); //--Debug
Looking for help guys....what am I missing ...thanks in advance ....
UPDATE
So I have a second class that does all the CoreBluetooth setup and discovery
Discovery.h
#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>
#import "SensorDev.h"
// -------------------------------------------------------------------------------
//UI Setup/Protocols
// -------------------------------------------------------------------------------
#protocol DiscoveryDelegate <NSObject>
- (void) discoveryDidRefresh;
- (void) discoveryStatePoweredOff;
#end
#interface Discovery : NSObject
+(Discovery*) sharedInstance;
#property (nonatomic, assign) id<DiscoveryDelegate> discoveryDelegate;
#property (nonatomic, assign) id<SensorTagDelegate> peripheralDelegate;
// -------------------------------------------------------------------------------
// Actions
// -------------------------------------------------------------------------------
- (void) startScanningForUUIDString:(NSString *)uuidString;
- (void) stopScanning;
- (void) connectPeripheral:(CBPeripheral*)peripheral;
- (void) disconnectPeripheral:(CBPeripheral*)peripheral;
// -------------------------------------------------------------------------------
// Access to the devices
// -------------------------------------------------------------------------------
#property (readonly, nonatomic) NSMutableArray *foundPeripherals;
#property (retain, nonatomic) NSMutableArray *connectedPeripherals;
#end
Discover.m (extract)
#import "Discovery.h"
extern NSString *SR1Device9DOFServiceUUIDString; //346D0000
extern NSString *SR1Device9DOFCharacteristicUUIDString; //346D0001-12A9-11CF-1279-81F2B7A91332
#interface Discovery() <CBCentralManagerDelegate, CBPeripheralDelegate> {
CBCentralManager *_centralManager;
BOOL _pendingInit;
}
#end
#implementation Discovery
#pragma mark - Setup
+ (Discovery*) sharedInstance
{
static Discovery *this = nil;
if (!this)
this = [[Discovery alloc] init];
return this;
}
- (id) init
{
self = [super init];
if (self) {
_pendingInit = YES;
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
_foundPeripherals = [[NSMutableArray alloc] init];
_connectedPeripherals = [[NSMutableArray alloc] init];
}
return self;
}
#pragma mark - CoreBluetooth Services
// -------------------------------------------------------------------------------
// CoreBluetooth Start/Stop Scanning
// -------------------------------------------------------------------------------
- (void)startScanningForUUIDString:(NSString *)uuidString
{
NSLog(#"- (void) startScanningForUUIDString"); //--Debug
[_centralManager scanForPeripheralsWithServices:
[NSArray arrayWithObjects:SR1Device9DOFServiceUUIDString, nil] options:nil];
}
- (void)stopScanning
{
NSLog(#"- (void) stopScanning"); //--Debug
}
// -------------------------------------------------------------------------------
// CoreBluetooth Connect/Disconnect
// -------------------------------------------------------------------------------
- (void) connectPeripheral:(CBPeripheral*)peripheral
{
NSLog(#"- (void) connectPeripheral"); //--Debug
if (peripheral.state == CBPeripheralStateDisconnected) {
[_centralManager connectPeripheral:peripheral options:nil];
}
}
- (void) disconnectPeripheral:(CBPeripheral*)peripheral
{
NSLog(#"- (void) disconnectPeripheral"); //--Debug
[_centralManager cancelPeripheralConnection:peripheral];
}
- (void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
NSLog(#"- (void) didConnectPeripheral"); //--Debug
SensorDev *tag = nil;
// Create a service instance.
tag = [[SensorDev alloc] initWithPeripheral:peripheral controller:_peripheralDelegate];
[tag start];
if (![_connectedPeripherals containsObject:tag])
[_connectedPeripherals addObject:tag];
[_peripheralDelegate sensorTagDidChangeStatus:tag];
[_discoveryDelegate discoveryDidRefresh];
}
This isn't running either ...
The reason why the classes were not running as there was nothing calling them. The class associated to the view controller was not calling the class:
BLEController.h
#import <Foundation/Foundation.h>
#interface BLEController : NSObject {
enter code here
NSMutableArray *_periphralItems;
}
#end
BLEController.m
#import "SensorDev.h"
#import "Discovery.h"
#import "BLEController.h"
#interface BLEController() <DiscoveryDelegate, SensorTagDelegate>
{
BOOL _selfSelection;
}
#end
#implementation BLEController
- (void)awakeFromNib
{
[[Discovery sharedInstance] setDiscoveryDelegate:self];
[[Discovery sharedInstance] setPeripheralDelegate:self];
_periphralItems = [NSMutableArray new];
}
- (void) discoveryDidRefresh
{
}
- (void) discoveryStatePoweredOff
{
}
- (void)sensorTagDidChangeStatus:(SensorTag *)tag
{
if(tag.peripheral.state == CBPeripheralStateConnected) {
//Do something
}
}
#end
The awakeFromNib allows me to call the other classes....

"No visible #interface" error with method

CJSHWork as a class is defined in CJSHWork.h and CJSHWork.m. In CJSHWork.h I have:
#interface CJSHWork : NSObject
#property (nonatomic, copy) NSString *name;
#property (nonatomic, copy) NSString *title;
#property (nonatomic, copy) NSString *url;
-(id) initWithName:(NSString *)name filename:(NSString *)title content:(NSString *)url;
#end
In CJSHWork.m I have:
- (id) initWithName:(NSString *)name title:(NSString *)title content:(NSString *)url
{
self = [super init];
if (self)
{
_name = name;
_title = title;
_url = url;
}
}
And I have, in CJSHDataController.m,
import "CJSHWork.h"
...
CJSHWork *work = [[CJSHWork alloc] initWithName:#"" title:allWorks[i][1] url:url];
This gets the error "No visible #interface for CJSHWork declares the selector initWithName title url".
What is going on here, and how can I fix it?
Your method name is initWithName:title:content: not initWithName:title:url:

unable to import yahoo contacts in ios app getting BadExcess error

I have downloaded this project from https://github.com/yahoo/yos-social-objc .
I have changed the ConsumerKey,
ConsumerSecret
and ApplicationId but When I Run the app it crashes. It gives an error of BAD-Excess.
Does anyone has any idea of this??
please advise
Thanks
Basically its just downloaded project from yahoo's developer's page still.
This is my Complete code
SocialSampleAppDelegate.h file
#import <UIKit/UIKit.h>
#import "YOSSession.h"
#class SocialSampleViewController;
#interface SocialSampleAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
SocialSampleViewController *viewController;
YOSSession *session;
NSMutableDictionary *oauthResponse;
BOOL launchDefault;
}
#property BOOL launchDefault;
#property (nonatomic, readwrite, retain) YOSSession *session;
#property (nonatomic, readwrite, retain) NSMutableDictionary *oauthResponse;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet SocialSampleViewController *viewController;
- (void)getUserProfile;
- (void)createYahooSession;
- (void)handlePostLaunch;
#end
SocialSampleAppDelegate.m
#import "SocialSampleAppDelegate.h"
#import "SocialSampleViewController.h"
#import "YOSUser.h"
#import "YOSUserRequest.h"
#import "NSString+SBJSON.h"
#implementation SocialSampleAppDelegate
#synthesize window;
#synthesize viewController;
#synthesize session;
#synthesize launchDefault;
#synthesize oauthResponse;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
launchDefault = YES;
[self performSelector:#selector(handlePostLaunch) withObject:nil afterDelay:0.0];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
launchDefault = NO;
if (!url) {
return NO;
}
NSArray *pairs = [[url query] componentsSeparatedByString:#"&"];
NSMutableDictionary *response = [NSMutableDictionary dictionary];
for (NSString *item in pairs) {
NSArray *fields = [item componentsSeparatedByString:#"="];
NSString *name = [fields objectAtIndex:0];
NSString *value = [[fields objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[response setObject:value forKey:name];
}
self.oauthResponse = response;
[self createYahooSession];
return YES;
}
- (void)handlePostLaunch
{
if(self.launchDefault) {
[self createYahooSession];
}
}
- (void)createYahooSession
{
// create session with consumer key, secret and application id
// set up a new app here: https://developer.yahoo.com/dashboard/createKey.html
// because the default values here won't work
self.session = [YOSSession sessionWithConsumerKey:#"MYConsumer KEy"
andConsumerSecret:#"MY Secret"
andApplicationId:#"My APPID"];
if(self.oauthResponse) {
NSString *verifier = [self.oauthResponse valueForKey:#"oauth_verifier"];
[self.session setVerifier:verifier];
}
BOOL hasSession = [self.session resumeSession];
if(!hasSession) {
[self.session sendUserToAuthorizationWithCallbackUrl:nil];
} else {
[self getUserProfile];
}
}
- (void)getUserProfile
{
// initialize the profile request with our user.
YOSUserRequest *userRequest = [YOSUserRequest requestWithSession:self.session];
// get the users profile
[userRequest fetchProfileWithDelegate:self];
}
- (void)requestDidFinishLoading:(YOSResponseData *)data
{
NSDictionary *userProfile = [[data.responseText JSONValue] objectForKey:#"profile"];
// NSLog(#"%#",[userProfile description]);
if(userProfile) {
[viewController setUserProfile:userProfile];
}
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
#end
SocialSampleViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
[nicknameLabel setText:#"loading..."];
}
- (void)setUserProfile:(NSDictionary *)data
{
NSString *welcomeText = [NSString stringWithFormat:#"Hey %# %#!",
[[data objectForKey:#"profile"] objectForKey:#"givenName"],
[[data objectForKey:#"profile"] objectForKey:#"familyName"]];
[nicknameLabel setText:welcomeText];
}
info plist

Objective C Calculator Programming Variable

Okay, so I've been working on the Stanford iOS development course that they have posted for free online. I've been working on figuring out how to make a programable variable. It has been working fine so far, aside from the fact that I think the following lines of code are programming the variable to be #"x=" instead of the previous number entered.
The View Controller:
#import "ViewController.h"
#import "CalculatorBrain.h"
#interface ViewController()
#property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;
#property (nonatomic) BOOL userPressedSomethingElse;
#property (nonatomic, strong) CalculatorBrain *brain;
#end
#implementation ViewController
#synthesize display;
#synthesize inputHistory;
#synthesize userPressedSomethingElse;
#synthesize userIsInTheMiddleOfEnteringANumber;
#synthesize brain = _brain;
- (CalculatorBrain *)brain
{
if (!_brain) _brain = [[CalculatorBrain alloc] init];
return _brain;
}
NSString *xValue = #"0";
- (IBAction)enterPressed
// A specific action if enter is pressed
{
[self.brain pushOperand:[self.display.text doubleValue]];
self.userIsInTheMiddleOfEnteringANumber = NO;
if (self.userPressedSomethingElse)
{
self.inputHistory.text = [self.inputHistory.text stringByAppendingString:#" "];
}
self.userPressedSomethingElse = NO;
}
- (IBAction)variableChanged:(id)sender
{
if (self.userIsInTheMiddleOfEnteringANumber)
{
[self enterPressed];
}
NSString *operation = [sender currentTitle];
xValue = [self.brain programVariable:operation];
self.inputHistory.text = [self.inputHistory.text stringByAppendingString:#"X="];
self.inputHistory.text = [self.inputHistory.text stringByAppendingString:xValue];
}
The Calculator Brain (the .m one):
#import "CalculatorBrain.h"
#interface CalculatorBrain()
#property (nonatomic,strong) NSMutableArray *operandStack;
#end
#implementation CalculatorBrain
#synthesize operandStack = _operandStack;
- (NSMutableArray *) operandStack
{
if (!_operandStack)
{
_operandStack = [[NSMutableArray alloc] init];
}
return _operandStack;
}
- (void) pushOperand:(double)operand
{
NSNumber *operandObject = [NSNumber numberWithDouble:operand];
[self.operandStack addObject:operandObject];
}
- (double)popOperand
{
NSNumber *operandObject = [self.operandStack lastObject];
if (operandObject) [self.operandStack removeLastObject];
return [operandObject doubleValue];
}
- (NSString *) programVariable: (NSString *) operation
{
double result = [self popOperand];
NSString *resultString = [NSString stringWithFormat:#"%.2d",result];
return resultString;
}
The .h Calculator Brain:
#import <Foundation/Foundation.h>
#interface CalculatorBrain : NSObject
- (void) pushOperand: (double) operand;
- (double) performOperation: (NSString *) operation;
- (NSString *) programVariable: (NSString *) operation;
#end
The button that is pushed says "x=", and because of some tracing statements I added, I have figured out that this is being set to xValue. However, I don't know how to fix it... Any ideas?
In your variableChanged:method, you possibly want if (!self.userIsInTheMiddleOfEnteringANumber) at the beginning. Note the logical negation, which I derive the need from the sense of your variable name. I see no way that variable is set, so I trust you are properly setting it elsewhere in your app.
Also, change the variable xValue to a instance variable on ViewController. It is currently a global static variable. If you have more than one ViewController objects created, you will have problems.