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 4617810
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:10:38+00:00 2026-05-22T02:10:38+00:00

I am porting cpp code into Objective C. In cpp we can add a

  • 0

I am porting cpp code into Objective C.

In cpp we can add a class as friend class to another class and use all its public functions and variables.

I know that Objective C does not support friend class concept.

How do i make a class as a friend to another class in Objective C

  • 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-22T02:10:39+00:00Added an answer on May 22, 2026 at 2:10 am

    If you have two tightly-coupled classes, then you can use some simple tricks to expose a simpler public interface. For example,

    In Banana.h:

    @interface Banana : NSObject
    - (BOOL)isPeeled;
    @end
    

    In Monkey.h:

    @interface Monkey : NSObject
    - (void)eat:(Banana *)aBanana;
    @end
    

    In BananaPrivate.h:

    @interface Banana (PrivateMethods)
    - (void)peel;
    @end
    

    Then your Monkey.m file can import BananaPrivate.h to get the private functions. If you’re writing a framework, then you don’t include BananaPrivate.h in your framework headers.

    This is the same way encapsulation is done in C. In my opinion it’s significantly less broken than the friend keyword in C++, but it’s beyond the scope of this answer to explain why.

    You can also expose private member variables this way if you implement Banana as a class cluster, but that’s kind of insane and I don’t recommend it. If you need even closer coupling between classes you might want to use C idioms for that part of the code.

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

Sidebar

Related Questions

I'm porting some open source code so that it can build on another c++
I was porting the cpp code to objective C .And i came across this
I am new to Objective C. I am porting the cpp code to Objective
I am porting cpp code to Objective C. In cpp void create(INT32u &uLen) {
I was porting from cpp to Objective C. Objective C: [pPacket SetHeaderSequenceNumber:static_cast<char>(m_transmitSequenceNumber + ASCII_ZERO)];
Porting code from 32bit to 64bit. Lots of places with int len = strlen(pstr);
I'm porting old VB6 code that uses the Winsock control to C#. I haven't
I'm currently porting a heap of code that has previously only been compiled with
I found a strange issue when porting my code from Visual Studio to gcc.
After porting a code segment from Windows to Mac OS X, I found it

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.