I am trying to inherit from MKPinAnnotation in this manner:
MKPinAnnotationView -->MyPoint-->PhotoPoint
but I get an error in Xcode saying PhotoPoint can't be defined without a base class.
Here is my code in MyPoint.h:
#import <MapKit/MKPinAnnotationView.h>
#interface MyPoint:NSObject<MKAnnotation>{...}
then in PhotoPoint.h:
#interface PhotoPoint:MyPoint
and this is where I get the error...does anyone have any ideas?
In PhotoPoint.h you need to import MyPoint.h.
#import "MyPoint.h"
#interface PhotoPoint : MyPoint
Related
I am working on a framework project where I have a sub class implemented from base class. When I prepare build I am just making sub class public but not the base class which results the following lexical error:
Lexical or Preprocessor Issue Group
But if I make the base class also public then it is okay. But I don't want to expose base class to the outer world. I mean don't want to make base class public.
Here is definition of base class
#interface BaseClass : NSObject
- (void)baseFunction;
#end
definition of sub class:
#interface SubClass : BaseClass
- (void)subFunction;
#end
and the header file:
#import <UIKit/UIKit.h>
#import <FileUtil/SubClass.h>
Please let me know how I can overcome the situation. Thanks in advance :)
You need to add this function declaration in #implementation file with Extension so it will hide from other user who will use your framework.
BaseClass.h
#interface BaseClass : NSObject
#end
BaseClass.m
#interface BaseClass ()
//its private method for out side class
- (void)baseFunction;
#end
#implementation BUViewController
#end
How by this example you can get some idea how to make private method to hide from others.
I am inexperienced with Objective-C and this is my first attempt at anything Swift. I Can't get Xcode to compile. ( I may also be missing a necessary line or two, but if I get it to compile, I can usually figure out the rest )
I've been all over docs and getting started, I don't know enough to know the answer if it's there:
http://bustoutsolutions.github.io/siesta/guide/objc/
https://bustoutsolutions.github.io/siesta/api/
My Code:
// MyAPI.swift
import Siesta
import SwiftyJSON
#objc class MyAPI: Service {
internal static let instance = MyAPI(baseURL:"https://api.example.com")
}
// ViewController.mm
#import "ViewController.h"
#import "PlateScanner.h"
#import "Plate.h"
#import "MyProject-swift.h"
...
- (IBAction)callAPI:(id)sender
{
[[MyAPI.instance resource:#"/profile/"] child:#"123"];
}
-(void)resourceChanged: (BOSResource*) resource event: (NSString*) event {
if([event hasPrefix:#"NewData"]) {
NSLog(#"%#",[resource text]);
}
}
...
I get the following 2 errors from ViewController.mm:
1. line starting "[[MyAPI": No visible #interface for 'MyAPI' declares the selector 'resource:'
2. line starting "-(void)reso": Expected a type
From this I understand that my ViewController is not understanding the necessary BOSResource type, but I don't know how to get the swift library imported properly?
Xcode generated code:
//MyProject-swift.h
...
SWIFT_CLASS("_TtC10MyProject5MyAPI")
#interface MyAPI : BOSService
+ (MyAPI * _Nonnull)instance;
#end
...
With Error in line starting "#interf...": Cannot find interface declaration for 'BOSService', superclass of 'MyAPI'
Any help is greatly appreciated!
I've got a dylib framework with some UIView subclasses made in swift which I've done to use the new #IBDesignable and #IBInspectable stuff.
So lets say I've got a UITextField subclass in there named MyTextField.swift like this:
MyTextField.swift
#IBDesignable class MyTextField: UITextField {
// some properties etc.
// content is irrelevant
}
Now it compiles and works well in InterfaceBuilder so far so good. But what I need to do is import this special subclass into my Objective C implementation of the controller to set a property in code at runtime.
The framework (named myViews) has a header called myViews.h which I am able to import into the controllers header like this:
MyViewController.h:
#import myViews;
#import <UIKit/UIKit.h>
#import "myViews.h"
#interface MyViewController : UIViewController
#property(weak, nonatomic) IBOutlet MyTextField *txtName; // <-- This is the problem!
#end
This is where I'm stuck! So the class MyTextField is unknown from the imported headers. The myViews.h was automatically generated. I've tried to import the bridging-headers in there without success.
myViews.h:
#import <UIKit/UIKit.h>
//! Project version number for myViews.
FOUNDATION_EXPORT double myViewsVersionNumber;
//! Project version string for myViews.
FOUNDATION_EXPORT const unsigned char myViewsVersionString[];
// In this header, you should import all the public headers of your framework
// using statements like #import <myViews/PublicHeader.h>
#import <myViews/MyTextField-Swift.h> // <-- This is what I've tried to import here which doesn't work as well.
Hope anybody may help me out. Thanks in advance.
In your objective-c class, try importing your swift module like this:
#import "<ModuleName>-Swift.h"
Where ModuleName is the name of the module containing the swift code
Here is my Constants.h:
#import Foundation;
typedef NS_ENUM(NSUInteger, BarcodeType) {
kNormalBarcode,
kNoBarcode,
kGenericBarcode,
kInvalidBarcode,
kComicBarcode
};
#interface Constants : NSObject
#end
And here is a function that uses it:
.h:
#interface Helper : NSObject
- (BarcodeType)barcodeType:(NSString *)barcode;
.m:
#import "Constants.h"
...
- (BarcodeType)barcodeType:(NSString *)barcode
{
return kInvalidBarcode;
}
Why am I getting this warning on my function, and what do I need to change to fix it?
Conflicting return type in implementation of 'getBarcodeType:': 'id' vs 'BarcodeType' (aka 'enum BarcodeType')
This code seemed to work fine with older versions of Xcode.
Thanks!
Check your .h file. My guess is your declaration of the method uses id, which conflicts with your definition in the .m file that returns type BarcodeType. NSEnum values aren't objects, so id isn't valid. You'll want to correct the declaration so the return type matches the implementation.
please i got errors when i try to read the content of a variable in view2 which was initialized in view1, i explain :
view1 is named RechercherViewController
view2 is named StationsSurLaCarteViewController
RechercherViewController.h :
#property (nonatomic,copy) NSString *typeCarburantChoisi;
RechercherViewController.m :
#synthesize typeCarburantChoisi;
StationsSurLaCarteViewController.h
#import "RechercherViewController.h"
#interface StationsSurLaCarteViewController : UIViewController {
IBOutlet AideStationsSurLaCarteViewController *aideStationsSurLaCarteViewController;
IBOutlet UITextField *textField;
}
#end
StationsSurLaCarteViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
textField.text=RechercherViewController.typeCarburantChoisi;
}
when building the app, i got actually two errors :
error: expected specifier-qualifier-list before 'StationsSurLaCarteViewController'
and
error: accessing unknown 'typeCarburantChoisi' class method
thx for help :)
First of all you have defined an instance property typeCarburantChoisi but in your StationsSurLaCarteViewController.m code you are trying to access kind of a class property (btw, there is no such thing in Objective-C). You will instead need a reference to your RechercherViewController instance and ask it for the property – this will resolve the second compiler error.
Regarding the first error I am not really sure what happened here. Maybe you have an error in your RechercherViewController.h file?
In any case, you should rather not import the interface file into StationsSurLaCarteViewController.h. Instead, use
#class RechercherViewController;
and import the full declaration in your implementation file StationsSurLaCarteViewController.m only.
Also, did you mix up AideStationsSurLaCarteViewController and RechercherViewController in your example?