Best way to handle repetitive task in objective C?

Discussion in 'Mac Programming' started by jonahhh, Jan 19, 2011.

  1. jonahhh macrumors newbie

    Joined:
    Jun 11, 2010
    #1
    Objective C(and programming in general) newbie here. I have a specific goal project I'm working on, but I'm not sure the best way to tackle it. I came up with a pseudo code solution that I'm slowly translating to obj c, but I'm not sure if I'm wasting my time coming at it all wrong. Am I headed down the wrong path? Is this a good forum to post in?

    I don't mind learning too much high level stuff, but on the other hand I'd rather spend one day or even a week copying and pasting than three or four months just to get started. Thanks for any help!

    Here's the problem:
    I have 15 objects each exactly the same, other than the name. Each object has 20 parameters. Each of these parameters can be set by the user to "connected" "disconnected", or "random". I want to output a text file in binary 0=off 1=on. So the result would be like this: object_12_11100110110000111000

    Here's the general plan
    When the program launches:
    a)If there are less than x(15 in this case) objects make a new one. Call it object_0 +1.

    b)Each object is to have a page to be dynamically named object 1,2,3, ect.(Unsure how to do this in Interface builder) I will build one template page with all the named paramaters and a user selectable UI box for each. I need to figure out way to number all the parameters behind the scenes too. The user could then go to an object's page and edit each of the parameters. Then they hit a button to make a text file.

    c) Start with object_1 and append blank "parameters" string.

    As long as parameters length is less than y(20 in this case) check UI box z(z starts as zero)+1. Set this as the new z value.

    If UI box says "connected" append 1, "disconnected" append 0 or "random" then pick 0 or 1 randomly and append that.

    When parameters = 20, store that info, object_1 +1 and repeat c), unless object_20 then print out a objects 1 through x to a text file.

    Example code would be great! BTW Is there a list of all obj c syntax? There is so much, it would really help.

    I think my algorithm is sound, but I'm not sure if I should use the algorithm to create the program and have the hard values coded into the file I distribute or what. I'm not sure how I would go about that.

    I've built something similar to this using the command prompt where the user hit 1,2,3, but nothing this in depth. It was also really easy to copy the text file and just change the number for the objects.

    I'd like to give the user an interface, an option to save their settings to come back latter and make a lot of usability improvements like that. But combining the GUI and the code is really throwing me off. I'm not sure how to deal with Interface Builder and window generation. Switching between the two modes is hard.

    There's also a lot more functionality I want to add later like loading and parsing the output to fill in the settings of the program.
     
  2. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
    It would help if you told us a little bit of how you have developed the objective C experience you are using for this task. Which books, courses, websites, etc... you have used to get to this point. Are there any other programming languages you have used successfully before?

    B
     
  3. jonahhh thread starter macrumors newbie

    Joined:
    Jun 11, 2010
    #3
    I'm not sure how much I know now matters...I'll put in the effort to get the program done. I feel I'm fairly knowledgeable with the foundations of programming(details below if it really matters). But i'm a novice because it's really about putting that knowledge into practice.

    I'd rather not spend a ton of time working on an algorithm and then start over again when I get to the next step, but it looks like that's what I have to do. I'd really prefer to get started writing code I'll actually use.:(

    I guess using "best" in my thread title was a (failed) attempt to get some strong opinions on how to tackle the problem.

    How to integrate IB is tripping me up a great deal. I would like to use IB to make the GUI, but jumping between IB and the code is making it slower to write/learn the actual language.

    It also feels like there are more ways to solve a problem in Obj C than I'm used to. This is bad because in theory I can think of quite a few solutions to my problem. Without knowing the language 100% I don't know if my theories can actually be put into practice.

    Basically, if I was dealing with 1 object, 20 parameters and using the terminal I would be done. If I was working in IB I would have really ugly code, but be close to done. It's a combination of generative loops AND Interface Builder.

    I haven't found any resources that talk about combining the two.

    I want to utilize IB most effectively and write code without getting frustrated shoehorning it into IB. It seems like IB is not Object Oriented? Like I said I want my 15 windows without building 15 windows and linking each of the 20 parameters in each window!

    I'd rather not, but it seems like brute force copy/paste is the easiest way to tackle this. Maybe I should stay 95% inside interface builder and just do it the slow way.

    I mean should I make an "object" class init and alloc 15 of them and name then object1..15? The object class would have 20 parameters so make setParamater1..20 ? Link each popup menu on the interface builder? All by hand it will be incredibly slow and boring.

    I think this would hurt adding functionality later that I want like being able to parse a text file and set all the parameters according to that text, too.

    A Loop to make and name instances of the "object" class until there are x(15).

    A loop inside the "object" class to make y(20) setParameter1..Y. This is making my head hurt trying to figure out...

    A Loop to name and create the windows to control the "objects". For each popupbutton it would send a set 1, 0 or call a utility class to run a special random number generator and get 1 or 0 and set it.

    NSLog @”%...x", parameter1...x,? Still figuring out how to send this to the GUI.

    And still, maybe it's better to use append strings to do all this.

    Books:
    Programming in Objective C - Kochan (avoids guis)
    Objective C for Absolute Beginners - Bennett, Lees, Fisher (more about ipod)
    Learning Cocoa with Objective-C Davidson (2002 edition, outdated. I read that the 2010 edition is better.... is it worth it?)

    Details:
    I did 1 semester about a year ago we used C++ with Dev-C++, but we tackled most problems procedurally. We built the standard mad libs, calculator, and number guessing games and others.

    Then we used Alice to learn about methods and classes, the whole object oriented thing. Alice was nice because it was easy to see how programs were broken!:) Alice was harder, but I think the GUI of the program itself gave me the most frustrations. OOP makes sense to me, but I feel it's more work in some cases.

    I remember the foundations well. I got good grades on my programs. I actually like to comment, so I never got graded down on that!

    I think forgetting much of the specific syntax is actually good overall. I'm not frustrated with Obj-c for not being the same. It seems incredibly more verbose though. Objective C seems more flexible and more options means more confusion. ;P

    Anyway, writing things out is useful, so I've at least got that.
     
  4. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #4
  5. jonahhh thread starter macrumors newbie

    Joined:
    Jun 11, 2010
    #5
    Bump for ideas/source files. Apple's source examples have been pretty helpful, but I've only found a few that apply so far. A class/method list would be really helpful too, I know I'm being dumb and overlooking it, but I can't find it. Runtime reference was only somewhat helpful.
    http://developer.apple.com/library/...rence/objcruntimeref/Reference/reference.html

    For lack of anything better to do I've built a currency convertor and the standford calculator is my 3rd calculator. Didn't help. So I built a single page of of what I want to do too, but I'm still unsure how best to tackle 10 pages. I'm thinking I ought to make the parameters a table rather than pop-up buttons. I'm not sure how Objective c handles tables. Can I have 20 columns(for each of the parameters) and 3 rows(for on/off/random) and have a selection in each column, or should I have 1 column and 3 rows iterate 20 times?

    Since I was stuck on that I started working on the other random number generators in my project. I have 10 that are in the same range 0-1(including decimals) and another 10 that are all in different ranges. I ended up making unique classes to handle this. Is there a better way? Feels like I'm doing it wrong.

    User control of the range of the random number generators isn't working well and is really tedious to setup. There has got to be another way.

    Got printing to a text file working kinda. Pasteboard and parsing an input text file are giving me a lot of problems, but I need to have all 10 of my Object windows set up before I can really test this.

    I feel like I'm about 30% done and once I figure out how to handle the object window creation I'll be closer to 70 or 80%, but I very well could be underestimating how difficult parsing a text file will be.
     
  6. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #6

Share This Page