Xcode Build errors (newbie) - objective-c

Here's my code:
(from SQLiteDB.h)
#import <sqlite3.h>
#interface SQLiteDB : NSObject {
NSString *dbPath;
int databaseKey;
sqlite3 *db;
}
//#property (nonatomic, copy) NSString *db;
#property (nonatomic, copy) NSString *dbPath;
#property (nonatomic) sqlite3 *db;
#property (nonatomic) int databaseKey;
#end
===============
(from SQLiteDB.m)
#import "SQLiteDB.h"
#implementation SQLiteDB
#synthesize db, dbPath, databaseKey;
#end
===============
(from SampleAppDelegate.m)
#import "ReaderSampleAppDelegate.h"
#import "ReaderSampleViewController.h"
#implementation ReaderSampleAppDelegate
#synthesize window;
#synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// create the d/b or get the connection value
SQLiteDB *dbInstance = [[SQLiteDB alloc] init]; // Error here <---------
}
==================
Error is: SQLiteDB undeclared.
I thought I did declare it in SQLiteDB.h? How do I fix this?

use
#import "SQLiteDB.h"
in SampleAppDelegate.m

In SampleAppDelegate.m include the following line:
#import "SQLiteDB.h"

You need:
#import "SQLiteDB.h" in SampleAppDelegate.m or .h

You need to #import SQLiteDB.h into SampleAppDelegate.m

You probably need to #import "SQLiteDB.h" in SampleAppDelegate.m

Related

Swift 5/Objective-C Expected Type parsing issue QMImageView

I just upgraded this application to swift 5 and am getting a parsing issue; expected type error. I tried importing the uikit and foundation but that didn't seem to resolve the issue. I'm still pretty new to swift so I'm not sure exactly what the error means.
//
// QMImageView.h
// QMChatViewController
//
// Created by Andrey Ivanov on 27.06.14.
// Copyright (c) 2014 Quickblox. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "QMImageLoader.h"
#protocol QMImageViewDelegate ;
typedef NS_ENUM(NSUInteger, QMImageViewType) {
QMImageViewTypeNone,
QMImageViewTypeCircle,
QMImageViewTypeSquare
};
#interface QMImageView : UIImageView
/**
Default QMUserImageViewType QMUserImageViewTypeNone
*/
#property (assign, nonatomic) QMImageViewType imageViewType;
#property (weak, nonatomic, readonly) UITapGestureRecognizer *tapGestureRecognizer;
#property (strong, nonatomic, readonly) NSURL *url;
#property (weak, nonatomic) id <QMImageViewDelegate> delegate;
- (void)setImageWithURL:(NSURL *)url;
- (void)setImageWithURL:(NSURL *)url
placeholder:(UIImage *)placehoder
options:(SDWebImageOptions)options
progress:(SDWebImageDownloaderProgressBlock)progress
completedBlock:(SDExternalCompletionBlock)completedBlock;
- (void)setImageWithURL:(NSURL *)url
title:(NSString *)title
completedBlock:(SDExternalCompletionBlock)completedBlock;
- (UIImage *)originalImage;
#end
#protocol QMImageViewDelegate <NSObject>
- (void)imageViewDidTap:(QMImageView *)imageView;
#end
error
Expected a type QMImageView.h
photo of error

'expected a type' errors in Obj-C using Parse

I'm declaring three related classes for my program and getting numerous 'Expected a type' and 'Unknown type name' errors. Having looked at similar problems on StackOverflow, I thought that perhaps I was having an issue with circular dependencies, but I can't seem to resolve the errors by using #class forward declarations. What do I need to do to get this project to build?
BQUser.h
#import <Parse/Parse.h>
#import "BQQuestion.h"
#import "BQAnswer.h"
#interface BQUser : PFUser<PFSubclassing>
#property (retain) NSString *userDescription;
#property (retain) PFFile *userImage;
- (BQQuestion *) addNewQuestion:(NSString *) question; //expected a type
- (BQAnswer *) addNewAnswer:(NSString *) answer toQuestion:(BQQuestion *) question; //expected a type
- (void) likeAnswer: (BQAnswer *) answer; //expected a type
#end
BQQuestion.h
#import <Parse/Parse.h>
#import "BQUser.h"
#interface BQQuestion : PFObject<PFSubclassing>
#property (retain) BQUser *user; //unknown type name 'BQUser'; did you mean 'PFUser'?
#property (retain) NSString *questionText;
#property (retain) NSArray *answers;
#property int answerCount;
+ (NSString *)parseClassName;
#end
BQAnswer.h
#import <Parse/Parse.h>
#import "BQUser.h"
#import "BQQuestion.h"
#interface BQAnswer : PFObject<PFSubclassing>
#property (retain) BQUser *user; //unknown type 'BQUser'; did you mean 'PFUser'?
#property (retain) BQQuestion *question; //unknown type name 'BQQuestion'
#property (retain) NSString *answerText;
#property int votes;
+ (NSString *)parseClassName;
#end

#end in c-objective

Ok, it may be a dumb mistake. But I can't figure out what xcode wants from me.
So here is the header file
#import <Foundation/Foundation.h>
#import "TableViewController.h"
#end
#interface Settings : NSObject
- (id)init: (TableViewController*) TableControll;
#end
If there is no #end before interface it says expected identifier or (, and suggests adding #end there. If there is an #end it says end must appear in objective-c contex.
Ideas?
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMessageComposeViewController.h>
#interface TableViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,MFMessageComposeViewControllerDelegate>
{
ControllerType controllerType;
}
#property (retain, nonatomic) IBOutlet UITableView *tableView;
#property (retain, nonatomic) NSArray *dataArray;
#property (retain, nonatomic) NSArray *imageArray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andType:(ControllerType)type;
#end
You have a #end before the #interface declaration in your Settings.h file.
It should read:
#import <Foundation/Foundation.h>
#import "TableViewController.h"
#interface Settings : NSObject
- (id)init: (TableViewController*) TableControll;
#end
Also, you haven't included the #import directive for ControllerType in your TableViewController.h which may be why you're getting obscure errors in your Settings.h file.

own delegate - function work in 50%, something is wrong

i've got own delegate for my own class.
MainMenuViewDelegate
#import <Foundation/Foundation.h>
#class MainMenuView;
#protocol MainMenuViewDelegate <NSObject>
-(void) mainMenuViewLibrary:(MainMenuView*)controller withString:(NSString*)string;
#end
MainMenuView.h
#import <UIKit/UIKit.h>
#import "WorkspaceView.h"
#import "MainMenuViewDelegate.h"
#interface MainMenuView : UIView
#property (nonatomic,weak) id <MainMenuViewDelegate> delegate;
....
#end
MainMenuView.m
#implementation MainMenuView
#synthesize delegate;
...
-(void)library:(id)sender{
//test
NSLog(#"it's work");
NSString *string = #"some text";
[delegate mainMenuViewLibrary:self withString:string];
NSLog(#"finish");
}
WorkspaceView.h
#import <UIKit/UIKit.h>
#import "MainMenuViewDelegate.h"
#interface WorkspaceView : UIView <MainMenuViewDelegate> {
int menuStatus;
UILabel *label;
}
#property int menuStatus;
#property (nonatomic, retain) UILabel *label;
#end
WorkspaceView.m
#import "WorkspaceView.h"
#import "MainMenuView.h"
#implementation WorkspaceView
#synthesize menuStatus;
#synthesize label;
....
-(void) mainMenuViewLibrary:(MainMenuView*)controller withString:(NSString*)string{
[label setText: string];
}
#end
The problem appears when i press btnLibrary and invokes -(void)library:(id)sender function.
console print it's work, then my delegate function is invokes, but i don't see any change in my label (placed in WorkspaceView), and in finish console print finish.
None of your objects is set as the delegate so the delegate is nil - messages sent to nil are silenced. Nothing happens.
If it is not a problem, put the NSLog in:
-(void) mainMenuViewLibrary:(MainMenuView*)controller withString:(NSString*)string;
in your WorkspaceView and check whether the method is called.
Hope that helps.

'Existing ivar 'delegate' for unsafe_unretained property 'delegate' must be __unsafe_unretained

I'm getting the error above, but unsure how to go about fixing it. This is my code:
.h:
#import <UIKit/UIKit.h>
#protocol ColorLineDelegate <NSObject>
-(void)valueWasChangedToHue:(float)hue;
#end
#interface ColorLine : UIButton {
id <ColorLineDelegate> delegate;
}
#property (nonatomic, assign) id <ColorLineDelegate> delegate;
#end
.m:
#import "ColorLine.h"
#implementation ColorLine
#synthesize delegate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
#end
The error occurs in the synthesize line. I can't find a problem though.
Use this syntax:
#interface SomeClass : NSObject {
id <SomeClassDelegate> __unsafe_unretained delegate;
}
#property (unsafe_unretained) id <SomeClassDelegate> delegate;
Looks like your project might be using ARC then properties should be declared this way:
#import <UIKit/UIKit.h>
#protocol ColorLineDelegate <NSObject>
-(void)valueWasChangedToHue:(float)hue;
#end
#interface ColorLine : UIButton
#property (nonatomic, weak) id <ColorLineDelegate> delegate;
#end
I had the same problem when I used old example code which did not feature ARC in my ARC project. It seems that you do not need to put the variable declarations into the interface definition any more. So your code should work like this:
h:
#import <UIKit/UIKit.h>
#protocol ColorLineDelegate <NSObject>
-(void)valueWasChangedToHue:(float)hue;
#end
#interface ColorLine : UIButton {
// Get rid of this guy!
//id <ColorLineDelegate> delegate;
}
#property (nonatomic, assign) id <ColorLineDelegate> delegate;
#end
.m:
#import "ColorLine.h"
#implementation ColorLine
#synthesize delegate;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
#end
Perhaps a bit late but to be "ARC compliant", you simply have to replace
#property (nonatomic, assign) id <ColorLineDelegate> delegate;
by
#property (nonatomic, strong) id <ColorLineDelegate> delegate;
Bye.
If you want a weak property, this also works.
#interface MyClass : NSObject {
__weak id <MyClassDelegate> _delegate;
}
#property (nonatomic, weak) id <MyClassDelegate> delegate;
you can also use
#dynamic delegate
in the implementation instead of synthesize.