Sunday, January 21, 2018

#1 2010-11-15 07:51:40 am

From:: Philadelphia
Registered: 2003-11-12
Posts: 237

I need help with some porting from AppleScript to Objective-C

I've been running circles on this for days and am getting no where. I am trying to build an app that will use a grid based on columns and number of lines on a page and write out coordinates for ad placements on that page (there will be nothing but ads).

Each page will have 3 cols and 133 lines (rows). I have a list of ads that come to me with ad name, # of cols and # of inches. - ((Ad1, 3, 3), (Ad2, 2,1), (Ad3, 1, 2)...

The inch conversion is 16 lines per inch.

Here's my process - I have two arrays/list - pCoords and uCoords (p for potential, u for used). For each ad I determine the potential starting coordinates - so in the list above the first ad would have a list of potential starting coordinates (listed as col/row) of ((1,1), (1,2), (1,3), (1,4)...(1, 133)) - I am ignoring for height in the potential array as I account for it later on in a conditional, I'm really just looking for starting column.

First loop through there will obviously be no conflict, starting point is 1, 1, I run a method that gets all the coordinates the first ad will take and put it into the uCoords array/list. The rest of the ads I need to pull their potential coordinates from the pCoords array/list and check it against the uCoords. Where I don't get a match is the next starting point.

I prototyped this in AppleScript because it is easier for me to think in that language and it worked fine. Taking the ad list above, here are the starting and ending coordinates (these are listed row/col):

{{"Ad1", "1::1", "44::3"}, {"Ad2", "45::1", "60::2"}, {"Ad3", "45::3", "74::3"}}

Ad 1 takes 3 cols and is 44 lines in height, ad 2 starts in col 1 right below the first ad and is 2 cols wide, which leaves room in col 3 to beign the 3rd ad, which is only 1 col. wide and therefore fits. If I change the 3rd ad to a 2 col one and rerun the script it recognizes that you cannot start a 2 col ad in the 3rd col and moves it to col 1, below the 2nd ad:

{{"Ad1", "1::1", "44::3"}, {"Ad2", "45::1", "60::2"}, {"Ad3", "61::1", "90::2"}}

When I port this over to Objective-C I run into issues. With the third ad as a 1 col ad the app is not seeing the available space in col 3 for a 1 col ad, it is placing it in col 1 below the 2nd ad, instead of col 3, next to the second ad. If I add more ads it stacks them all in col 1.


I'm not sure if it is how I am setting the arrays up that are effecting this (I've tried row/col and col/row with the same results) or if it is how obj-c's [array containsObject: obj] method checks sequentially through the array but AS's array does not contain {contents of subarray} seems to look at the whole array at once.

I can post the script's if someone wants to see the work (they're kind of long, unlike this short post big_smile )

Thanks for any help.

Last edited by RIRedinPA (2010-11-15 07:56:05 am)



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)