Converting NSMutableArray to PPC?

Discussion in 'Mac Programming' started by trey5498, Aug 11, 2008.

  1. trey5498 macrumors regular

    Joined:
    Jun 16, 2008
    #1
    If some remember I am trying to convert Intel to PPC. I have found the switches to turn to make it possible. However I have to convert some of the code from Objective-C 2.0 to 1.0

    2.0 code:
    Code:
    arrSelections1 = [[NSArray alloc] initWithObjects: cse211djq, wei408djq, arc118djq, cse211clq, arc118clq, hubatlabclq, nrng514clq, wei408clq, tur2215clq, arcatlabbwq, b105110bwq, cse211bwq, hscmdlbwq, hubatlabbwq, lawpclabbwq, lbw3radbwq, nrnatlabbwq, tur2215bwq, weiatlabbwq, nil];
    


    1.0?? Is this the proper way??? Or do I have to set each value by itself?

    Code:
    my arrSelections1 = NSMutableArray->alloc->init;
    
    arrSelections1->addObject(cse211djq, wei408djq, arc118djq, cse211clq, arc118clq, hubatlabclq, nrng514clq, wei408clq, tur2215clq, arcatlabbwq, b105110bwq, cse211bwq, hscmdlbwq, hubatlabbwq, lawpclabbwq, lbw3radbwq, nrnatlabbwq, tur2215bwq, weiatlabbwq);
    

    I also want to know if there is anything else I need to change besides the way to add and read the array?

    Would be great to know if there was a site that explained the difference between the two with help of the conversions. Any? Lastly how do I make a universal code?


    Also will there be an issue with the interface if built in xcode 3.0?
     
  2. lucasgladding macrumors 6502

    Joined:
    Feb 16, 2007
    Location:
    Waterloo, Ontario
    #2

    If the array is meant to be stored in an instance variable, you may want to retain the array and release it in dealloc, but other than that nothing would change. If your array was not mutable in ObjC 2, it shouldn't need to be under ObjC 1.

    The syntax for ObjC 1 is nearly identical to ObjC 2. The big changes IMHO were properties, fast enumerators and garbage collection. Please, someone correct me if I am missing something obvious.

    You can find an introduction to ObjC 2 at http://theocacao.com/document.page/510. This should give you an idea of what was new to ObjC 2 so you can figure out what the differences are. Apple also has what's new documents on the developer site explaining things in more detail.

    For any simple project, making something universal is probably only build settings.

    Finally, if you target 10.4 in your nib, you will get warnings for any compatibility problems.
     
  3. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    Yes, your second code listing isn't really Objective-C at all, what you have written is more the behind the scenes C representation of an Objective-C call, it's has nothing to do with Obj-C 1.0 vs. 2.0. As trey says, Objective-C 2.0 isn't really much different from 1.0 and that's separate from changes of Tiger Cocoa vs. Leopard Cocoa. As far as I know, not much has changed in NSMutableArray, and your first code should still work fine. Objective-C 2.0 and the latest API revisions of Cocoa both work the same running under PPC as well as i386 (Intel). If you want to compile for PPC, you just need to change the compile options for your target in Xcode. It sounds like you found those though? Are you using the latest Xcode on Leopard?
     
  4. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #4
    Yes I am using the latest version of Leopard and Xcode 3.0. Target is 10.4 and architecture is ppc. It complains about the enumeration of the code throws an error about linking and stops.

    Code:
    
    @implementation AppController
    //sets points of prninstall and prninstall104 to point to PrnInstall.m and PrnInstall104.m for method calls
    PrnInstall * prninstall;
    PrnInstall104 * prninstall104;
    
    int i;
    int tmp;
    int tmp1;
    NSString *stTmp;
    
    
    -(id) init
    {
    	
    	if ([super init]) {
    		//initializes the arrays and the points to call other methods
    		arrPRN = [[NSMutableArray alloc] init];
    		arrPRNint = [[NSMutableArray alloc] init];
    		arrSelections = [[NSMutableArray alloc] init];
    		arrInstalled = [[NSMutableArray alloc] init];
    		prninstall = [[PrnInstall alloc] init];
    		prninstall104 = [[PrnInstall104 alloc] init];
    		
    	}
    	return self;
    }
    -(void) dealloc
    {
    	//releases the arrays from memory
    	[super dealloc];
    	[arrPRN release];
    	[arrPRNint release];
    	[arrSelections release];
    	[arrSelections1 release];
    	
    }
    
    
    
    
    
    - (void)awakeFromNib {
    	//calls the method to check the verison of OS and sets the value to the approiate value
    	[self CheckInstalled];
    	if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4) {
    		stDvrChk = @"Tiger";
    	} else {
    		stDvrChk = @"Leopard";
    	}
    	arrSelections1 = [[NSArray alloc] initWithObjects: cse211djq, wei408djq, arc118djq, cse211clq, arc118clq, hubatlabclq, nrng514clq, wei408clq, tur2215clq, arcatlabbwq, b105110bwq, cse211bwq, hscmdlbwq, hubatlabbwq, lawpclabbwq, lbw3radbwq, nrnatlabbwq, tur2215bwq, weiatlabbwq, nil];
    		
    } 
    	
    
    - (IBAction)NextButton:(id)sender 
    {
    	// Color Printer 
    	//Checks for each one check button if they are checked and adds the correct values to the appropiate arrays
    	if([arc118clq state]==NSOnState) {
    		[arrPRN addObject:@"ARC-118-CLQ"];
    		[arrPRNint addObject:@"ARC118ClQ"];
    		[arrSelections addObject:arc118clq];
    		
    	 } 
        17 more of these
    
    }
    
    for(NSButton *button in arrSelections) [button setState:NSOffState];
    2 warnings of enum here and there is 4 of these total.
    
    
    
     
  5. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #5
    Sounds like it's told you what is wrong... you are using Fast Enumeration, and this is an Objective-C 2.0 feature that is not supported in previous versions. You will need to change this to another control structure like a for-loop that uses count: as it's upper limit, or a while loop using the NSEnumerator, as described here:
    http://developer.apple.com/document.../apple_ref/occ/instm/NSArray/objectEnumerator

    -Lee

    P.S. This is, technically, my fault as I insisted on the use of Fast Enumeration because I think it's great. I didn't know you'd be targeting lower OS releases at the time.
     
  6. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #6
    I didn't either, We had a lab that refuses to upgrade to intel and are still using 10.3 ppc.

    so this:

    Code:
    for(NSButton *button in arrSelections) [button setState:NSOffState];
    
    becomes this?

    Code:
    NSButton *button;
    for(i=0; i<[arrSelections count]; i++) {
         button = arrSelections[i];
         [button setState:NSOffState];
    }
    
    anything else in the above code screaming to need to be changed?
     
  7. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    That looks good. This is perhaps just a matter of style, but I would assign the value of count to an int before the loop, and use that variable in the loop condition. Probably not strictly necessary, but it saves calls (even though they are fast) and just "feels" better to me with a mutable array, since the array could be modified within the loop (though this could prove devastating anyway, and should not be done).

    -Lee
     
  8. lucasgladding macrumors 6502

    Joined:
    Feb 16, 2007
    Location:
    Waterloo, Ontario
    #8
    You probably want to read the NSArray documentation if you are new to ObjC. You can't get the object at i like you would with C. Note: it wouldn't work in ObjC 2 either. Also, make sure you have declared i. I can't remember offhand if NSUInteger was supported in Tiger, so that may need to be uinteger instead. Compiler warnings should tell you what you need for any other problems.

    Code:
    NSUInteger i;
    NSButton *button;
    for(i=0; i<[arrSelections count]; i++) {
         button = [arrSelections objectAtIndex:i];
         [button setState:NSOffState];
    }
    
     
  9. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #9
    Pretty sure NSInteger and NSUInteger were introduced with Leopard, and are Leopard-only. So I think you would have to change those for a pre-10.5 target.
     
  10. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #10
    Oy, should have read more carefully before I said it looked good.

    To the OP: There is no operator overloading in objective C, so any and all access to Objects is through message passing, either using [Object Method:argument] syntax or (for Obj-C 2.0 only) the . operator for properties. The dot operator is syntactic sugar for a message pass, anyway, though.

    -Lee
     
  11. trey5498 thread starter macrumors regular

    Joined:
    Jun 16, 2008
    #11
    I meant:

    button = [arrSelections objectAtIndex:i];


    However my brain got crossed with perl (was working on a piece of perl code as well).

    Got it, having issues revering back to Intel to build the proper Intel one, with the original fast enumeration, but I think I left something out as it give me a warning of "local declaration of button hides instance value" for:

    for(NSButton *button in arrSelections) [button setState:NSOffState];


    I will look at it tomorrow as it time for me to go home. Thank you for your help at correcting my code crossovers lol.
     
  12. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #12
    Why are you switching the SDK to 10.4 to build for PPC? You can build universal binaries just find with the 10.5 SDK.
     

Share This Page