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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:34:52+00:00 2026-06-14T13:34:52+00:00

I wrote a BinaryReader class in Objective-C that can extract an NSString from bytes

  • 0

I wrote a BinaryReader class in Objective-C that can extract an NSString from bytes created using C#’s BinaryWriter.Write(string). It seems to work great, but when I call:

    BinaryReader *binaryReader = [[BinaryReader alloc] initWithData:dataArray];
    NSString *strName = [binaryReader readString];
    // strName is not nil, but the value is no longer correct (seems to have been erased)

I stepped into the readString method, and everything looks great (the string is correct) up until the method returns (I think ARC is kicking in).

Why would this be happening?

Here’s my readString method:

-(NSString *)readString
{
    NSUInteger bytesCount = (NSUInteger)[self read7BitEncodedInt];
    const void *byteData = [_data bytes] + _dataIndex;

    NSString *returnValue =
        [[NSString alloc] initWithBytes:byteData length:bytesCount encoding:NSUTF8StringEncoding];

    _dataIndex += bytesCount;
    return returnValue;
}

The returnValue contains the proper string right before the method returns.

By request, here’s my init function for BinaryReader.

-(id)initWithData:(NSData *)theData
{
    self=[super init];
    if(self != nil)
    {
        _dataIndex = 0;
        _data = theData;
    }
    return self;
}

and the relevant part of header

@interface BinaryReader : NSObject
{
    @private
    NSData *_data;
    int _dataIndex;
}
  • 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-06-14T13:34:53+00:00Added an answer on June 14, 2026 at 1:34 pm

    Are you sure the result is actually broken? The code you posted seems fine and there should be no ownership/memory issues when compiled with ARC.

    Lately there have been issues reported with lldb (the debugger) not showing correct values in some cases. Try to log the result using NSLog.

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

Sidebar

Related Questions

I wrote a PHP script that retrieves values from a MySQL Query. I used
I want to write a routine that receives some jpeg frames from a server
I wrote a process explorer using C with GUI interface. I want to add
I wrote a collada loader for my model viewer. Write now it loops through
I wrote a Flickr search engine that makes a call to either a public
I am decoding a file using the following method: string outFileName = zfoFileName.Replace(.zfo, _tmp.zfo);
I'm working on an application in C# and need to read and write from
How do I read a raw byte array from any file... Dim bytes() as
As discussed before , when a BinaryReader or BinaryWriter gets closed, its underlying Stream
I wrote a php code that display error in red color. But somehow, this

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.