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

  • Home
  • SEARCH
  • 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 1085339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:40:36+00:00 2026-05-16T22:40:36+00:00

I have a user class that I use through the iPhone application, this is

  • 0

I have a user class that I use through the iPhone application, this is the init and initWithUser functions from my user class (A SUBCLASS OF NSobject), when I use the initWithUser function I get the warning described after the code. please advise.

// serialize.h 
#import <Foundation/Foundation.h>

@protocol Serialize

// serialize the object to an xml string
-(NSString*)ToXML;

@end


// user.h
#import <Foundation/Foundation.h>
#import "Serialize.h"
#import "Contact.h"


@interface User : NSObject <Serialize> {

NSString *email;
NSString *firstName;
NSString *lastName;
NSString *userId;
NSString *userName;
NSString *password;

NSMutableArray *contactList;

}

@property (nonatomic,copy) NSString *email;
@property (nonatomic,copy) NSString *firstName;
@property (nonatomic,copy) NSString *lastName;
@property (nonatomic,copy) NSString *userId;
@property (nonatomic,copy) NSString *userName;
@property (nonatomic,copy) NSString *password;
@property (nonatomic, retain) NSMutableArray *contactList;

//-(id)init;
-(id)initWithUser:(User *)copyUser;

@end



// user.m 
#import "user.h"


@implementation User

@synthesize email;
@synthesize firstName;
@synthesize lastName;
@synthesize userId;
@synthesize userName;
@synthesize password;
@synthesize contactList;

-(id)init
{
    // call init in parent and assign to self
    if( (self = [super init]) ) 
    {          
        // do something specific 
        contactList = [[NSMutableArray alloc] init];

    }
    return self;
}

-(id)initWithUser:(User *)copyUser
{
    if( (self = [self init]) ) {           

        email               = copyUser.email;
        firstName           = copyUser.firstName;
        lastName            = copyUser.lastName;
        userId              = copyUser.userId;
        userName            = copyUser.userName;
        password            = copyUser.password;

        // release contactList initialized in the init
        [contactList release];
        contactList         = [copyUser.contactList mutableCopy];
    }

    return self;
}

- (void)dealloc
{
    // TODO: 
    [contactList removeAllObjects];
    [contactList release];
    [super dealloc];
}

// implementation of serialize protocol
-(NSString*)ToXML
{
    return @""; 
}

and I use it in the main controller this way

- (void) registerNewUser {

    RegistrationViewController *regController = [[RegistrationViewController alloc] init] ;

    regController.newUser = [[User alloc] initWithUser:self.user];

    [self.navigationController pushViewController:regController animated:YES];
    [regController release];

}

the line

regController.newUser = [[User alloc] initWithUser:self.user];

gives me the following error, and its been driving me nuts for a couple of days:

incompatible Objective-c types ‘struct User*’, expected ‘struct NSString *’ when passing argument 1 of ‘initWithUser:’ from distinct Objective-c type

any help and guidance is appreciated

  • 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-16T22:40:37+00:00Added an answer on May 16, 2026 at 10:40 pm

    The problem is you have an ambiguous selector. Because alloc returns id, the call to initWithUser: has become ambiguous. NSUserDefaults also has an initWithUser: function which takes a string. The compiler thinks you’re trying to use that one. Change the line to

    regController.newUser = [(User*)[User alloc] initWithUser:self.user];
    

    and everything should work as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which I use to enumerate through lists from my database.
I have a class that looks something like this: class User < ActiveRecord:Base has_many
I have a class that defined a user defined operator for a TCHAR*, like
I have implemented a LoginAccess class that prompts the user to enter their active
I have a Filter Method in my User Class, that takes in a list
I have a class Bar that has a user-defined list of config keys and
I have a class called UserInfo that contains details about a given user. There
I'm wanting to have a strongly typed user control that accepts the class PaginatedList<T>
I am designing a test application (Using NUnit) that will have to navigate (through
I'm going to have a nav bar that lets a user sort through a

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.