objective-c

How should I pass an int into stringWithFormat?

I am try to use stringWithFormat to set a numerical value on the text property of a label but the following code is not working. I cannot cast the int to NSString. I was expecting that the method would know how to automatically convert an int to NSString. What do I need to do here? - (IBAction) increment: (id) sender { int count = ...

Streaming audio from server to iPhone

I'm looking to stream some audio files I have on my server to an iPhone-client application I'm writing. Some of the audio files can be rather large in size, even after compression. My question is, is there a Cocoa framework that helps me with buffering the audio so it becomes available to the user while the rest is being brought down the...

String munging in Objective-C with NSAttributedString.

I have an NSAttributedString s and an integer i and I'd like a function that takes s and i and returns a new NSAttributedString that has a (stringified) i prepended to s. It looks like some combination of -stringWithFormat:, -initWithString:, and -insertAttributedString: would do it but I'm having trouble piecing it together without a l...

NSTask not picking up $PATH from the user's environment

I don't know why this method returns a blank string: - (NSString *)installedGitLocation { NSString *launchPath = @"/usr/bin/which"; // Set up the task NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:launchPath]; NSArray *args = [NSArray arrayWithObject:@"git"]; [task setArguments:args]; // Set the...

Matching beginning of words in a NSString

Is there a method built in to NSString that tokenizes the string and searches the beginning of each token? the compare method seems to only do the beginning of a string, and using rangeOfString isn't really sufficient because it doesn't have knowledge of tokens. Right now I'm thinking the best way to do this is to call [myString comp...

NSString property: copy or retain?

Let's say I have a class called SomeClass with a string property name: @interface SomeClass : NSObject { NSString* name; } @property (nonatomic, retain) NSString* name; @end I understand that name may be assigned a NSMutableString in which case this may lead to errant behavior. For strings in general, is it always a good idea...

Any base64 library on iphone-sdk?

I'd like to do base64 encoding and decoding. But I could not find any support from iPhone SDK. Any suggestion? Thanks. ...

What's the easiest way to create an array of structs?

What's the easiest way to create an array of structs in Cocoa? ...

Does using lists of structs make sense in cocoa?

This question has spawned out of this one. Working with lists of structs in cocoa is not simple. Either use NSArray and encode/decode, or use a C type array and lose the commodities of NSArray. Structs are supposed to be simple, but when a list is needed, one would tend to build a class instead. When does using lists of structs make sen...

Obj C NSString returning class NSCFString

My objective here is really simple—I'm trying to set an NSString to some test data, then return the class (which should be NSString). Here's my code: NSString* stringer = [NSString stringWithFormat: @"Test"]; NSLog(@"%@", [stringer class]); Any help would be much appreciated, Thanks. ...

Getting the row of a NSButtonCell

I have a NSTableView that contains a NSButtonCell in one of the columns. I can set up the action that is called when the button is clicked in Interface Builder fine, but I can't find anyway to determine which row in the table that the button exists in. Is there any way to do this? Thanks. :) ...

Algorithm for 'Syncing' 2 Arrays

Array 1 | Array 2 ================= 1 | 2 2 | 3 3 | 4 5 | 5 | 6 What is a good algorithm to 'sync' or combine Array 2 into Array 1? The following needs to happen: Integers in Array 2 but not in Array 1 should be added to Array 1. Integers in both Arrays can be left alone. Integers in Array 1 ...

Obj C - Random @property error

Still new to Objective C, and I'm having some trouble that I just can't seem to figure out on my own. The error occurs twice for each of the first three @properties below, and is: error: "syntax error before ')' token". #import <Foundation/Foundation.h> @interface PolygonShape : NSObject { int *numberOfSides; int *minimumNu...

Blocks to KB/MB/GB from statfs on iPhone

I am using statfs() which gives me the free blocks available to a non-superuser. I am unsure how to convert this into KB/MB/GB. The values that are returned are: fundamental file system block size: 4096 total data blocks in file system: 3805452 free blocks in fs: 63425 free blocks avail to non-superuser: 63425 total file nodes in file...

Creating method in implementation without defining in header

How can I create a method in the @implementation of a class without defining it in the @interface? For example, I have a constructor that does some initialisation and then reads data from a file. I want to factor out the file-reading code into a separate method that I then call from within the constructor. I don't want to define this ...

Obj C - Understanding pointers...

I'm having a hell of a time understanding pointers in Objective C. They don't behave like I would assume based on various C tutorials. Example: // Define Name and ID NSString *processName = [[NSProcessInfo processInfo] processName]; NSNumber *processID = [NSNumber numberWithInt:[[NSProcessInfo processInfo] processIdentifier]]; // Prin...

iPhone Development - Creating a class like UIImagePickerController that returns data to parent

I have a situation where I have to take input from the user using multiple views (like Personal Information -> Professional Information -> Process Completed). I was wondering, how can I build a class like UIImagePickerController, which takes input from user and returns the data to parent class? Note that the view is also handled by this...

Objective C NSString* property retain count oddity

I have the following example class: Test.h: @interface Test : UIButton { NSString *value; } - (id)initWithValue:(NSString *)newValue; @property(copy) NSString *value; Test.m: @implementation Test @synthesize value; - (id)initWithValue:(NSString *)newValue { [super init]; NSLog(@"before nil value has retain count of %d...

How to sort a string of characters in objective-C?

I'm looking for an Objective-C way of sorting characters in a string, as per the answer to this question. Ideally a function that takes an NSString and returns the sorted equivalent. Additionally I'd like to run length encode sequences of 3 or more repeats. So, for example "mississippi" first becomes "iiiimppssss", and then could be s...

Manually setting a UIButton state

I UIButton using + buttonWithType: What I need to figure out is how to manually change the button state. There are times when I need it to be set to "disabled." I read through the UIButton documentation but I cannot seem to find anything about manually setting a button state. Any thoughts would be greatly appreciated. ...