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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:50:38+00:00 2026-06-06T05:50:38+00:00

I’m newer to Objective-C though I have worked in Java, C, and C++ and

  • 0

I’m newer to Objective-C though I have worked in Java, C, and C++ and I’m still learning Objective-C.

I have a socket, a receive data function, and a text view. As data comes in, I want to append it to the text view. Now my textview has some pre-populated text at the start. If in every call to receieve data that data comes in, I just get the current text of the text view, append it to itself in a nsstring with:

 NSString *oldtext = [mTextViewAlias text];
 NSString *toSend = [oldtext stringByAppendingString: oldtext];

and then set the text view to toSend, it works fine, and I see the data grow in my text view.

The problem is, I want to append:

 UInt8 buffer[len]; // which has data from the socket. len is set to amount of data on each call of receive data as follows
 int len = CFDataGetLength(df);

What I’ve been trying to do is convert a buffer to a nsstring and append. for example:

NSString *newdata = [NSString stringWithUTF8String: buffer];

it’s occurred to me that buffer may not terminate with a '\0' character so I’ve even created a new buffer called char newbuffer[len+1]; and copied buffer into it and added a \0 as the last character.

I can append the first time around on the first pass of new data, but the second append, appending to something that had chars from buffer appended to the text once before always crashes.

I did a little trick where if len > 10 assign buffer[10]='\0'. And it actually let me grab data twice before crashing the third time.

It seems I have one of two problems and I’m not sure how to fix it. One is I can only grab as much data as is in the buffer and somehow these nsstrings are depending on it and when I change the buffer when receiving data, it is called again it causes the crash. Or maybe it’s just still an issue with the '\0' not being there still though I don’t see how.

  • 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-06T05:50:40+00:00Added an answer on June 6, 2026 at 5:50 am

    Try something like this:

    NSMutableData *buffer = [[NSMutableData alloc] init];
    [buffer appendBytes:aCArray length:lengthOfaCArray];
    NSString *newdata = [[NSString alloc] initWithData: buffer encoding:NSASCIIStringEncoding];
    
    //When your finished with newdata and buffer, dont forget to release it
    //This might be done automatically if you have Automatic Reference Counting (ARC) on
    [newdata release];
    [buffer release];
    

    Full reference on the encoding types here.
    No guarantees this works as I wrote this code from a Windows machine and a couple tabs open at Apple’s developer site. But should help you in the right direction.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.