Pointer problem/ implicit conversion

Discussion in 'iOS Programming' started by Zelda, Aug 12, 2014.

  1. Zelda macrumors member

    Aug 10, 2014
    I am having an issue with this method.
    - initWithIn:(NSString *)inFile out:(NSString *)outFile{
    	self = [super init];
    	lastChord = nil;
    	DELTA = 256;
    	deltaDivide = 4;
        inData= [[NSFileHandle fileHandleForReadingAtPath:inFile]availableData] ;
    //[COLOR="Blue"]First problem above line is[/COLOR]: [COLOR="Red"]ARC Restrictions implicit conversion of an Objective c pointer to 'char*' is disallowed.[/COLOR]
          inLength = [inData length]);//2nd issue [COLOR="red"]Bad receiver type 'char*'[/COLOR]
          inData = [inData bytes];//3rd issue [COLOR="red"]Bad receiver type 'char*'[/COLOR]
    	pos = 0;
    	self->outFile = outFile;
    	track = [[NSMutableData alloc] init];
    	contents = [[NSMutableData alloc] init];
    	volume = 100;
    	return self;
    the header for this is:
    #import <UIKit/UIKit.h>
    @interface MidiViewController : UIViewController{
       char *inData;
    NSInteger inLength, pos;
    NSString *outFile;
    NSMutableData *track, *contents;
    NSString *lastChord;
    int DELTA, deltaDivide;
    int stepOffset, lastOffset;
    int volume, lastVolume;
    - initWithIn:(NSString *)inFile out:(NSString *)outFile;
    - (void) writeFile;
    - (void) buildTrack;
    - (void) writeVarTime:(int)value;
    - (void) writeChord:(NSString *)chord atDelta:(int)delta;
    - (void) closeLastChord:(int)delta;
    - (void) appendNote:(int)note state:(BOOL)on;
    Using iOS 7.1 sdk and xcode 5.1
    Any help is appreciated.
  2. chown33 macrumors 604

    Aug 9, 2009
    This code:
    @interface MidiViewController : UIViewController{
       char *inData;
    needs to be changed to this:
    @interface MidiViewController : UIViewController{
       NSFileHandle *inData;
  3. Zelda thread starter macrumors member

    Aug 10, 2014
     [COLOR="blue"]inData[/COLOR]= [[NSFileHandle fileHandleForReadingAtPath:inFile][COLOR="Red"]availableData[/COLOR]] ;
    I made the change you suggested and still have an issue, availableData is NSSdata and is an incompatible pointer type to inData(NSFileHandle)

    The code i am working on was created in 2005 in Xcode 2 for cocoa, and the author of the code states that although there are error warnings it still compiles and runs.

    Thanks for the reply chown33
  4. chown33 macrumors 604

    Aug 9, 2009
    Sorry, I didn't look closely enough at the methods you were trying to use. Try this code:
       NSData *inData;
    You can look this up yourself in the online class reference for NSFileHandle, then looking up the availableData method to see its return type. To find the online class reference, google search terms:
    NSFileHandle class

    No programmer in their right mind would purposely declare a type of char * when an object pointer is clearly demanded. I can only assume the author of the code you posted is insane, or is purposely misdeclaring types for some insane reason. There's no rational reason to declare the type as char *.

    It would make more sense to declare the type of indata as id than to declare it as char *. That is, this makes more sense than char *:
    id inData
    It's still ignorant because an NSData * is clearly the correct type, but at least it's more sane than char *.

    You should get better example code to work from. Or get used to unexplained failures when working with irrational code from almost a decade ago.
  5. Zelda thread starter macrumors member

    Aug 10, 2014
    Ok, using NSData or id both work in that particular method, though other issues are created in other methods, which is ok for now, i will eventually sort it out.
    The author has used various mismatched types throughout his code.
    I would love a more up to date example of what i am trying to do, however i have not found any suitable example thus far. Finding an appropriate search term is the vital key to success i imagine.

    I am looking for examples that take a string of musical notes or guitar chords and converts the string to a midi file.
    Thank you again, for your help.
  6. PhoneyDeveloper macrumors 68030


    Sep 2, 2008
    Where possible, NSFileHandle should never be used. It throws exceptions for any file system errors. This will cause your app to crash and burn if you don't have the correct try/catch around it.
  7. Zelda thread starter macrumors member

    Aug 10, 2014
    Agreed , I realise the example code is poorly written in several places for e.g.

    if( 'A' <= c && c <= 'G' ){		// a chord
    instead of using isEqualToString.

    However, the code in the methods are a basic guide line for what i need to accomplish, so i am going to re-write it from the beginning.

    Thanks again.

Share This Page