Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6580081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:58:50+00:00 2026-05-25T15:58:50+00:00

I have an API class, lets call it MyClass, which I want to be

  • 0

I have an API class, lets call it MyClass, which I want to be available thruout my whole application. Hence I put the #import into MyProject-Prefix.pch file.

Now, when I (in my appDelegate) initiate the class, I get the error message cannot init a class object..
I understand that I am initiating my class incorrectly, but I have no idea on how I should do it… and since this is not common for development (as I see it) there ain’t a lot of information to find thrue google (or I am searching wrong 😉 )

So, I have two questions:

  1. Any links for called “Creating Objective-C API’s for Dummys”? 😉
  2. Having a quick look at my code, what am I doing wrong?

This is my class:
MyClass.h

#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonDigest.h>

#import "NSStringAdditions.h"
#import "XMLRPCResponse.h"
#import "XMLRPCRequest.h"
#import "XMLRPCConnection.h"
/**
 * END required libs
 */

extern int EID;
extern NSString * SHARED_SECRET;
extern NSString * MODE;

@interface MyClass : NSObject

+ (id)initWithEid:(int)eid secret:(NSString*)secret mode:(NSString*)mode;
+ (NSArray*)web_invoice_infoWithOCR:(NSString*)ocr pno:(NSString*)pno;
+ (NSString*)the_digest:(NSString*)source;

@end

MyClass.m

#import "MyClass.h"

@implementation MyClass

int EID;
NSString * SHARED_SECRET;
NSString * MODE;

NSString * URL_LIVE;
NSString * URL_BETA;

#pragma mark init / dealloc

+ (id)init {
    self = [super init];
    if (self)
    {

    }
    return self;
}

+ (id)initWithEid:(int)eid secret:(NSString*)secret mode:(NSString*)mode
{
    self = [super init];
    if (self)
    {
        if (![[mode lowercaseString] isEqualToString:@"beta"] && ![[mode lowercaseString] isEqualToString:@"live"])
        {
            @throw ([NSException exceptionWithName:@"Invalid mode" reason:[NSString stringWithFormat:@"Invalid mode '%@' selected. Should either be 'beta' or 'live'", mode] userInfo:nil]);
        }

        EID = eid;
        SHARED_SECRET = secret;
        MODE = [mode lowercaseString];
    }

    return self;
}

+ (NSArray*)web_invoice_infoWithOCR:(NSString*)ocr pno:(NSString*)pno {    
    NSArray *params = [NSArray arrayWithObjects:ocr, EID, pno, [MyClass the_digest:[NSString stringWithFormat:@"%d:%@:%@", EID, ocr, SHARED_SECRET]], nil];

    NSLog(@"Array: %@", params);

    return params;
}

- (id)xmrpc_call_function:(NSString*)method parameters:(NSArray*)params
{
    // Not finished yet, Warning exists
}
[...]

Having a look at my code, you’ll notice the +(id)init function. I have tried -(id)init, -(id)initialize, +(id)initialize, +(void)initialize, -(void)initialize.

This is how I “load” my class in my AppDelegate:

[MyClass initWithEid:1234 secret:@"1234" mode:@"BETA"];

EDIT
I am trying to initiate my class the same way e.g. Flurry does. Example:

[FlurryAnalytics startSession:@"1234"];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:58:51+00:00Added an answer on May 25, 2026 at 3:58 pm

    You need to alloc it first:

    MyClass *myClass = [[MyClass alloc] initWithEid:1234 secret:@"1234" mode:@"BETA"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an API call in my application where I am checking the time
I have a library with only interfaces and basic objects, lets call it API.
I have a scenario in which I have REST API which manages a Resource
In java a class can implement Iterable which lets you use the foreach() statement
I have a API and it use a abstract class. I not familiar with
I have a simple Rails application with which I am trying to use the
I have an API that is dependent on certain state information between requests. As
I have an API consisting of ASP.NET webservices callable through GET/POST/SOAP. A new functionality
I have an API that can be implemented by various vendors. I can send
I have an API in the form of a JAR that I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.