Error "Unknown class method for" Hello: "selector in user structure

I am creating a structure for the company and I have completed all the code. Now I'm trying to pack it into a framework. As a test, I made a method with this name: -(void)Hello:(NSString *)worldText;

When I try to call it in the application using the framework using this code [CompanyMobile Hello:@"World"]; I get a compiler error that says

There is no known class method for the "Hello:" selector

.M in my structure is as follows:

 #import "Hello.h" @implementation Hello - (id)init { self = [super init]; if (self) { // Initialization code here. } return self; } -(void)Hello:(NSString *)world { } @end 

.h in my structure is as follows:

 #import <Foundation/Foundation.h> @interface Hello : NSObject -(void)Hello:(NSString *)world; @end 

.h in my application

 // // FMWK_TESTViewController.h // FMWK TEST // // Created by Sam on 6/15/11. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import <UIKit/UIKit.h> #import <companyMobile/Hello.h> @interface FMWK_TESTViewController : UIViewController @end 

.m in my application

 // // FMWK_TESTViewController.m // FMWK TEST // // Created by Sam Baumgarten on 6/15/11. // Copyright 2011 __MyCompanyName__. All rights reserved. // #import "FMWK_TESTViewController.h" @implementation FMWK_TESTViewController - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle - (void)viewDidLoad { [Badgeville Hello:@"Sam"]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // eg self.myOutlet = nil; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return YES; } @end 
+8
ios objective-c cocoa-touch compiler-errors ios-frameworks
source share
2 answers

You have defined Hello: as an instance method, but you are sending Hello: to the class. To define a class method, you write + (void)Hello: and not - (void)Hello:

+41
source share

refer to: https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html

to answer your question change

 @interface Hello : NSObject -(void)Hello:(NSString *)world; @end 

to

 @interface CompanyMobile : NSObject{ } +(void)Hello:(NSString *)world; @end 

and call the method [CompanyMobile Hello:@"world"];

+9
source share

All Articles