From Objective-C/Swift to App

Discussion in 'Mac Programming' started by unplugme71, Jun 2, 2014.

  1. unplugme71 macrumors 68030

    Joined:
    May 20, 2011
    Location:
    Earth
    #1
    So for the past few years, I've always been programming in languages like HTML, CSS, and PHP. I've developed some nice web applications in conjunction with MySQL DB. I also learned a little bit of C++ back in high school and made some cool DOS-like applications.

    Last year, I glimpsed through C and Objective-C and couldn't seem to understand it much. I was able to create a CLI of a calculator but that was it. Enter a number, followed by a symbol and another number and it output the result. Most likely I programmed it the way I remembered 10 years ago and probably didn't take advantage of the newer functions/classes.

    With Swift, Apple says its supposed to be a lot easier to learn for beginners, so I began reading the first 50 pages. It doesn't look too bad, but my question was, how do you go from the programming language to the visual piece of the app? Most of my programming in C++ produced a shell application with no GUI. PHP is similar. The only visually piece I was ever able to do is with HTML/CSS but it seems to much easier.

    For those who started programming, how did you transition from coding shell stuff to GUI? I'd like to make something simple like a calculator. How do you create the buttons, how do you assign it a value, and finally, how do you take those mouse inputs, calculate it, and output a result? I don't necessarily want the answer literally, but how you went on to learn how to do it so I can teach myself.
     
  2. mrxak macrumors 68000

    Joined:
    Apr 16, 2004
    Location:
    Drifting through space in a broken escape pod
    #2
    You gotta learn libraries. There are various kinds of libraries that do GUI, but the one you probably want to learn is Cocoa. Cocoa is what all of Apple's applications use for their interfaces.
     
  3. aaronvan Suspended

    aaronvan

    Joined:
    Dec 21, 2011
    Location:
    República Cascadia
    #3
    Download "Xcode Without the Code" free from the iBooks store. You will see visuals on creating and linking buttons, sliders, etc.
     
  4. unplugme71 thread starter macrumors 68030

    Joined:
    May 20, 2011
    Location:
    Earth
    #4
    Great, I'll give this a read as it'll get me familiar with Xcode as well.
     
  5. ghellquist macrumors regular

    Joined:
    Aug 21, 2011
    Location:
    Stockholm Sweden
    #5
    There are some great video courses on the itunes university free of charge if I remember right. This may be a different way to get a handle on the concepts.

    Basically, GUI programming is about turning things outside in compared to normal programming. Instead of your main programming controlling the world and getting things from the user it goes the other way round. The GUI application framework sets up the rules you need to follow.

    Your program becomes a lot of small snippets each doing tiny bits of the function. As example in doing a calculater, you write a small function "behind" the "7" key, and another small function between the "+" key. (Now, this is is a simplification). It takes a bit of turning around in the head and it does help if you can get input from different sources in finding the path.

    / Gunnar
     
  6. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #6
    I think you are doing the right thing and from what you say it sounds like you TRULY want to learn to program like I did. I spent almost a year learning before I made my first GUI and shortly after that an app in the app store.

    Also like aaronvan said, get xcode and start to learn that program if you haven't already. That 1 program allows you to build your buttons and such and write the code.

    Good Luck!
     
  7. brohan711 macrumors newbie

    Joined:
    Apr 10, 2012
    #7
    Basics

    While swift looks and functions in a way that is 'easier' for new developers, Cocoa and iOS/OSX libraries used to create the visual aspect of the applications have been written in Objective-C.

    I have a firm belief that if you want to know how iOS or OSX applications work you need to understand how Objective-C and the Cocoa Libraries work before you can inject Swift code.
     
  8. unplugme71 thread starter macrumors 68030

    Joined:
    May 20, 2011
    Location:
    Earth
    #8
    I followed the first two videos on how to build an iOS app from the Stanford U courses. The whole MVC concept cleared up a lot of questions I had. Even though its a bit outdated with Swift out now, at least I can learn the concept.

    ----------

    I guess it's also easier if you know what to program. I learned HTML, PHP, and MySQL by creating a personal website for me and logging hits in a database rather than a flat text file. Eventually I expanded into learning CSS and creating more complex functions within my personal site. However, I never picked up OOP with PHP and I somewhat regret not learning it earlier.

    The other thing is, books never really teach you why certain things are done or real-world concepts. I created a login/logout form using PHP Sessions and when I had someone look at it they pointed out so many flaws in the code. However, it did work but it wasn't secure, certain things were missing, certain things weren't needed. That's the other part of programming that I find complex. How do you "learn" these things other than from trial and error or having it reviewed by someone else?
     
  9. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #9
    There is no real secret to it. It just comes from reading a lot and asking questions on forums like this or on websites like Stack Overflow.

    Like most things in life it takes a lot of practice to get good at anything. Unfortunately there is no silver bullet other than taking the time to learn.

    On the plus side it is incredibly interesting when you get into it so that's good :).
     
  10. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #10
    That's how you learn these things. Kids don't learn how to ride a bicycle by reading a physics book. They learn by trying to ride one (and getting up and trying again when they fall and skin their knee). There might be a few kids who can skip doing all their arithmetic and math homework, but most people have to do the problem sets in order to gain enough skill to move on to subsequent stuff.

    So you learn to code by trying to code. Maybe failing. Maybe succeeding. Maybe having mistakes pointer out by a teacher or collaborator. But programming a better solution the 2nd, 3rd or Nth time.
     
  11. unplugme71 thread starter macrumors 68030

    Joined:
    May 20, 2011
    Location:
    Earth
    #11
    Yes but riding a bike is different. You either learn to balance yourself or not and fall..

    Whereas programming, you can write code that works, but can have security holes or maybe not the 'right' way to have written a function or something. It seems this area of programming is hard to find reference too unless you find an example online to copy from.
     
  12. AppleHater macrumors 6502a

    Joined:
    Jun 9, 2010
    #12
    Very true. There are hundreds of different ways to solve any given software engineering problems with different pros and cons. Some like clever solutions while others value stability and maintainability, for example.

    Writing a clean well-written code is certainly a skill of its own and usually doesn't matter which programming language you have started with, though.
     
  13. unplugme71 thread starter macrumors 68030

    Joined:
    May 20, 2011
    Location:
    Earth
    #13
    Yeah, I've gotten in the habit of spacing my lines of code out so its easy to read and also comment a lot.

    However in regards to the multiple ways, I guess that comes from trial and error. I'd have to hire someone to try and break the app (find ways to crash it or make it act in a way that was unintended) to verify its stability.
     

Share This Page