Expected Expression iOS Xcode - iphone

I'm trying to make a simple Calculator App and I'm following instructions in this video ( https://www.youtube.com/watch?v=Uzq41DRC0-Q )
However, when i got to about 9:14, I got an error saying "Expected Expression" and some mark before the else statement. I cannot post images now, so post me everything you know, please. I'm a newbie, so any help would be appreciated!
My code (ViewController.m) :
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction)ClearPressed:(id)sender {
}
- (IBAction)MinusPressed:(id)sender {
}
- (IBAction)PlusPressed:(id)sender {
}
- (IBAction)EqualsPressed:(id)sender {
}
- (IBAction)NumberPressed:(UIButton*)sender;{
NSInteger tag = sender.tag;
if (operatorPressed == FALSE) {
if (firstEntry == NULL) {
firstEntry = [NSString stringWithFormat:#"%li", (long)tag];
_OutputLabel.text = firstEntry;
}
}
else {
firstEntry = [NSString stringWithFormat:#"%#%li",firstEntry ,(long)tag];
_OutputLabel.text = firstEntry;
}
else { //HERE MY PROBLEM IS
if (secondEntry == NULL) {
secondEntry = [NSString stringWithFormat:#"%li", (long)tag];
_OutputLabel.text = secondEntry;
}
else {
if secondEntry = [NSString stringWithFormat:#"%#%li",firstEntry ,(long)tag];
_OutputLabel.text = secondEntry;
}
}
}
#end

You have two else statements. That's a no no.
- (IBAction)NumberPressed:(UIButton*)sender;{
NSInteger tag = sender.tag;
if (operatorPressed == FALSE) {
if (firstEntry == NULL) {
firstEntry = [NSString stringWithFormat:#"%li", (long)tag];
_OutputLabel.text = firstEntry;
}
}
else { // 1
firstEntry = [NSString stringWithFormat:#"%#%li",firstEntry ,(long)tag];
_OutputLabel.text = firstEntry;
}
else { // 2
if (secondEntry == NULL) {
secondEntry = [NSString stringWithFormat:#"%li", (long)tag];
_OutputLabel.text = secondEntry;
}
else {
if secondEntry = [NSString stringWithFormat:#"%#%li",firstEntry ,(long)tag];
_OutputLabel.text = secondEntry;
}
}
}
Check where I marked off with 1 and 2. The first else should be else if (someCondition). You can't have two else statements.

Related

OSAtomicIncrement32Barrier deprecated, how to solve this issue?

i'm trying Parse server on my ios app using Xcode14 and ios 16, I installed the pod Parse, but when I run the code I get the following warning message:
'OSAtomicIncrement32Barrier' is deprecated: first deprecated in iOS 10.0 - Use atomic_fetch_add() from <stdatomic.h> instead
Any help how I could fix this issue:
+ (instancetype)taskForCompletionOfAllTasks:(nullable NSArray<BFTask *> *)tasks {
__block int32_t total = (int32_t)tasks.count;
if (total == 0) {
return [self taskWithResult:nil];
}
__block int32_t cancelled = 0;
NSObject *lock = [[NSObject alloc] init];
NSMutableArray *errors = [NSMutableArray array];
BFTaskCompletionSource *tcs = [BFTaskCompletionSource taskCompletionSource];
for (BFTask *task in tasks) {
[task continueWithBlock:^id(BFTask *t) {
if (t.error) {
#synchronized (lock) {
[errors addObject:t.error];
}
} else if (t.cancelled) {
OSAtomicIncrement32Barrier(&cancelled); // error is here
}
if (OSAtomicDecrement32Barrier(&total) == 0) { // error is here
if (errors.count > 0) {
if (errors.count == 1) {
tcs.error = [errors firstObject];
} else {
NSError *error = [NSError errorWithDomain:BFTaskErrorDomain
code:kBFMultipleErrorsError
userInfo:#{ BFTaskMultipleErrorsUserInfoKey: errors }];
tcs.error = error;
}
} else if (cancelled > 0) {
[tcs cancel];
} else {
tcs.result = nil;
}
}
return nil;
}];
}
return tcs.task;
}
C11 has support for atomics so you can do something like:
#include <stdatomic.h>
// Declare an atomic int and initialize it to zero
atomic_int total;
atomic_init(&total, 0);
// Note: C17 and C23 allow safe direct initialization
// i.e. atomic_int total = 0;
// Operations such as ++total and --total are atomic
++total;
// Or alternatively
atomic_fetch_add(&total, 1);
atomic_fetch_sub(&total, 1);

Xml feed Parser for image

In my app, I used XML feed parser to get all the contents. But I got the null Array for Images which are included in parser.
My code for parsing is as follow:
#pragma mark MWFeedParserDelegate
- (void)feedParserDidStart:(MWFeedParser *)parser {
NSLog(#"Started Parsing: %#", parser.url);
}
- (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
NSLog(#"Parsed Feed Item: “%#”", item.title);
if (item)
{
[arr_itemIdentifier addObject:item.identifier];
[arr_itemTitle addObject:[item.title gtm_stringByUnescapingFromHTML]];
[arr_itemLink addObject:item.link];
[arr_itemdate addObject:item.date];
if( nil != item.updated )
{
[arr_itemupdated addObject:item.updated];
}
[arr_itemsummery addObject:item.summary];
NSString *renderedSummary = [item.summary stringByReplacingOccurrencesOfRegex:#"<[^>]*?>"
withString:#""];
[arr_itemRenderedSummary addObject:renderedSummary];
if( nil != item.content )
{
[arr_itemContent addObject:item.content];
}
}
NSLog(#"%#",item.description);
NSLog(#"item.enclosurs = %#",item.enclosures); // here i got null array so the for loop is not executed
for( NSDictionary *itemEnclosure in item.enclosures )
{
NSString *mimeType = [itemEnclosure objectForKey:#"type"];
if( [#"video/example" isEqualToString:mimeType] )
{
} else if( [#"image/example" isEqualToString:mimeType] )
{
NSString *itemAnchor = [itemEnclosure objectForKey:#"url"];
NSArray *captures = [itemAnchor arrayOfCaptureComponentsMatchedByRegex:DWFeedHTMLImageElementSrcValueRegex];
if( 0 < captures )
{
[arr_imageURL addObject:[itemEnclosure objectForKey:#"url"]];
}
[arr_thumbImage addObject:[itemEnclosure objectForKey:#"url"]];
//feedItem.thumbnailURL = feedItem.imageURL;
}
}
int k=0;
NSLog(#"arr_itemContent = %#",item.content);
NSLog(#"arr_itemdate = %#",item.date);
NSLog(#"arr_itemIdentifier = %#",item.identifier);
NSLog(#"arr_itemLink = %#",item.link);
NSLog(#"arr_itemRenderedSummary = %#",[arr_itemRenderedSummary objectAtIndex:k]);
NSLog(#"arr_itemsummery = %#",item.summary);
NSLog(#"arr_itemTitle = %#",item.title);
NSLog(#"arr_itemupdated = %#",item.updated);
k++;
}
- (void)viewDidLoad
{
NSURL *feedURL = [NSURL URLWithString:str_url];
feedParser = [[MWFeedParser alloc] initWithFeedURL:feedURL];
feedParser.delegate = self;
feedParser.feedParseType = ParseTypeFull; // Parse feed info and all items
feedParser.connectionType = ConnectionTypeAsynchronously;
[feedParser parse];
}
I got all the array information except images. I also get image url with content like: <p><a href="http://wpcore.mpf.s3.amazonaws.com/wp-content/uploads/2012/11/DDD-2121.jpg"> CONTENTS through log output by item.content

Accessing typedef enum function in iPhone?

I am using to typedef with somevalues in the header. how can i access the enum values and used in the application any one help me.
typedef enum{
INFO,PROD,WARN
}INFOS;
#interface ViewController : UIViewController{
INFOS infos;
}
-(NSString *)method:(INFOS)infovalue;
- (void)viewDidLoad
{
[self method:infos];
[super viewDidLoad];
}
- (NSString *) method:(INFOS) infovalue {
NSString *result = nil;
switch(infovalue) {
case INFO:
result = #"info";
break;
case PROD:
result = #"prod";
break;
case WARN:
result = #"warn";
break;
default:
result = #"unknown";
}
return result;
}
but the method not called after the view load. how can i do it.pls help me
typedef enum{
info = 1,
prod = 2,
warn = 3
}INFOS;
#interface ViewController : UIViewController{
//INFOS infos; you do not need this
}
-(NSString *)method:(INFOS)infovalue;
-(void)viewDidLoad;
{
[self method:info];
[super viewDidLoad];
}
- (NSString *) method:(INFOS) infovalue {
NSString *result = nil;
switch(infovalue) {
case 1:
result = #"info";
break;
case 2:
result = #"prod";
break;
case 3:
result = #"warn";
break;
default:
result = #"unknown";
}
return result;
}

Parsing xml content tag

my problem is that i cant parse the tag from a xml file.
It returns a null value, im testing it by using an NSLog with %#.
If someone could point me a solution i would be very thankful.
Here is the code:
BOOL processed = NO;
if (currentText) {
// Remove newlines and whitespace from currentText
NSString *processedText = [currentText stringByRemovingNewLinesAndWhitespace];
// Process
switch (feedType) {
case FeedTypeRSS: {
// Item
if (!processed) {
if ([currentPath isEqualToString:#"/rss/channel/item/title"]) { if (processedText.length > 0) item.title = processedText; processed = YES; }
else if([currentPath isEqualToString:#"/rss/channel/item/url"]) { if (processedText.length > 0) item.image = processedText; processed = YES; }
else if([currentPath isEqualToString:#"/rss/channel/item/category"]) { if (processedText.length > 0) item.category = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rss/channel/item/link"]) { if (processedText.length > 0) item.link = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rss/channel/item/guid"]) { if (processedText.length > 0) item.identifier = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rss/channel/item/description"]) { if (processedText.length > 0) item.summary = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rss/channel/item/content:encoded"]) { if (processedText.length > 0) item.content = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rss/channel/item/pubDate"]) { if (processedText.length > 0) item.date = [NSDate dateFromInternetDateTimeString:processedText formatHint:DateFormatHintRFC822]; processed = YES; }
else if ([currentPath isEqualToString:#"/rss/channel/item/enclosure"]) { [self createEnclosureFromAttributes:currentElementAttributes andAddToItem:item]; processed = YES; }
else if ([currentPath isEqualToString:#"/rss/channel/item/dc:date"]) { if (processedText.length > 0) item.date = [NSDate dateFromInternetDateTimeString:processedText formatHint:DateFormatHintRFC3339]; processed = YES; }
}
// Info
if (!processed && feedParseType != ParseTypeItemsOnly) {
if ([currentPath isEqualToString:#"/rss/channel/title"]) { if (processedText.length > 0) info.title = processedText; processed = YES; }
else if([currentPath isEqualToString:#"/rss/channel/item/url"]) { if (processedText.length > 0) item.image = processedText; processed = YES; }
else if([currentPath isEqualToString:#"/rss/channel/item/category"]) { if (processedText.length > 0) item.category = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rss/channel/description"]) { if (processedText.length > 0) info.summary = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rss/channel/link"]) { if (processedText.length > 0) info.link = processedText; processed = YES; }
}
break;
}
case FeedTypeRSS1: {
// Item
if (!processed) {
if ([currentPath isEqualToString:#"/rdf:RDF/item/title"]) { if (processedText.length > 0) item.title = processedText; processed = YES; }
else if([currentPath isEqualToString:#"/rss/channel/item/url"]) { if (processedText.length > 0) item.image = processedText; processed = YES; }
else if([currentPath isEqualToString:#"/rss/channel/item/category"]) { if (processedText.length > 0) item.category = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rdf:RDF/item/link"]) { if (processedText.length > 0) item.link = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rdf:RDF/item/dc:identifier"]) { if (processedText.length > 0) item.identifier = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rdf:RDF/item/description"]) { if (processedText.length > 0) item.summary = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rdf:RDF/item/content:encoded"]) { if (processedText.length > 0) item.content = processedText; processed = YES; }
else if ([currentPath isEqualToString:#"/rdf:RDF/item/dc:date"]) { if (processedText.length > 0) item.date = [NSDate dateFromInternetDateTimeString:processedText formatHint:DateFormatHintRFC3339]; processed = YES; }
else if ([currentPath isEqualToString:#"/rdf:RDF/item/enc:enclosure"]) { [self createEnclosureFromAttributes:currentElementAttributes andAddToItem:item]; processed = YES; }
}
call method:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell.
MWFeedItem *item = [itemsToDisplay objectAtIndex:indexPath.row];
if (item) {
NSLog(#"content = %#",item.content);//<-------------------------------------------Returns a NULL
// Process
NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : #"[No Title]";
NSString *itemSummary = item.summary ? [item.summary stringByConvertingHTMLToPlainText] : #"[No Summary]";
// Set
cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
cell.textLabel.text = itemTitle;
NSMutableString *subtitle = [NSMutableString string];
if (item.date) [subtitle appendFormat:#"%#: ", [formatter stringFromDate:item.date]];
[subtitle appendString:itemSummary];
cell.detailTextLabel.text = subtitle;
}
return cell;
}
Best Regards
While parsing every element the parser will return a whitespace character as a response because of new line / tabbing / carriage returns. If you have implemented a call back methods (delegates) of parser then check for null values, and i donno where you have implemented(in the sense,in which parser delegate method has this) the very first snippet.

How do I get TTTableViewDataSource to work with AddressBook

I would like to get a TTPickerTextField to search and get data from the build in AddressBook, and I understand I should make my own data source class that implements the TTTableViewDataSource protocol. But how do I implement it so that it connects correctly with the build in AddressBook? Im a newbie, so combining the Address Book Programming Guide for iOS and the API for TTTableViewDataSource is very confusing to me, so please help with some hints or even example(s).
Thank you
Here is an ABDataSource, that does exactly this. I'm using this in one of my apps. It will not work out of the box, because it depends on my 'DSMEmailAddress' class, but I hope it will point you in the right direction.
You may use this code under the terms of the zlib licence.
#interface ABDataSource : TTListDataSource {
ABAddressBookRef _addressBookRef;
NSMutableArray* _allItems;
NSMutableArray* _delegates;
}
+ (ABDataSource*)abDataSource:(BOOL)forSearch;
#end
#implementation ABDataSource
+ (ABDataSource*)abDataSource:(BOOL)forSearch {
ABDataSource* dataSource = [[[ABDataSource alloc] init] autorelease];
return dataSource;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc {
[_allItems release];
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// UITableViewDataSource
- (NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView {
return nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// TTTableViewDataSource
- (NSString*)tableView:(UITableView*)tableView labelForObject:(id)object {
DSMEmailAdress* field = object;
return field.name;
}
- (Class)tableView:(UITableView*)tableView cellClassForObject:(id)object {
return [DSMEmailAddressTableCell class];
}
- (void)tableView:(UITableView*)tableView prepareCell:(UITableViewCell*)cell
forRowAtIndexPath:(NSIndexPath*)indexPath {
cell.accessoryType = UITableViewCellAccessoryNone;
((TTTableViewCell*)cell).object =[_items objectAtIndex:indexPath.row];
}
- (void)search:(NSString*)text {
if (nil == _allItems) {
_addressBookRef = ABAddressBookCreate ();
NSArray* allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBookRef);
_allItems = [[NSMutableArray alloc] initWithCapacity:[allPeople count]]; // capacity is only a rough guess, but better than nothing
for (id record in allPeople) {
CFTypeRef emailProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonEmailProperty);
NSArray *emails = (NSArray *)ABMultiValueCopyArrayOfAllValues(emailProperty);
CFRelease(emailProperty);
for (NSString *email in emails) {
NSString* compositeName = (NSString *)ABRecordCopyCompositeName((ABRecordRef)record);
DSMEmailAdress* field = [[[DSMEmailAdress alloc] initWithName:compositeName mail:email] autorelease];
[compositeName release];
[_allItems addObject:field];
}
[emails release];
}
CFRelease(_addressBookRef);
_addressBookRef = nil;
[allPeople release];
allPeople = nil;
}
[_items release];
if (text.length) {
_items = [[NSMutableArray alloc] init];
for (DSMEmailAdress* mail in _allItems) {
if ([mail hasPrefix:text]) {
[_items addObject:mail];
}
}
if ([_items count]==0){
[_items release];
_items = nil;
}
} else {
_items = nil;
}
[_delegates perform:#selector(modelDidFinishLoad:) withObject:self];
}
#pragma mark TTModel
- (NSMutableArray*)delegates {
if (!_delegates) {
_delegates = TTCreateNonRetainingArray();
}
return _delegates;
}
- (BOOL)isLoadingMore {
return NO;
}
- (BOOL)isOutdated {
return NO;
}
- (BOOL)isLoaded {
return !!_allItems;
}
- (BOOL)isLoading {
return NO;
}
- (BOOL)isEmpty {
return !_items.count;
}
- (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {
}
- (void)invalidate:(BOOL)erase {
}
- (void)cancel {
[_delegates perform:#selector(modelDidCancelLoad:) withObject:self];
}
#end