I'm new to Swift, coming from C styled syntax languages (C#, java..). I've been given a past exam paper asking questions about Swift. I've came across one question;
A developer is building an iOS application that needs to obtain data over a network
connection. She is aware that it may take some time to process, but does not want the
application user interface to become unresponsive whilst the task executes. Outline the
steps she could take to achieve this, referring to the features available in the language
she might use.
The first thing that comes to mind is to use threads, and run this process on a separate thread, but from my understanding, threads do not exist in Swift. What's the best answer to this question?
Do not confuse language features with system features.
iOS certainly has ways to let you network asynchronously, and in particular to do a time-consuming download in the background. Indeed, by default all networking is asynchronous on a background thread; networking on the main thread would be a bug in your program. [The question you quoted was probably intended to elicit your knowledge of those features, of which it appears you have none.]
But all of that has nothing to do with what language you use to program iOS.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Im wondering how to kick-of projects for a single developer in proper way.
There are a lot of reasons why its not a good idea to just sitting down and hack the solution you want to reach without any plans or organisations.
In professional software engineering, there are a lot of required steps for planing a piece of software (like writing a vison and scope-document, doing requirements engineering and finaly planing the architecture).
But what are the common way for planning an application development endeavour for projects with just one single developer. For example: Do you use architecture-tempaltes like the well known arc42-Template. Do you thing its a littlebit unduly to doing such steps just for ideological reasons or is this the only right way?
What kind of Design-/Architecture-Templates so you use for planing projects?
Although you are a single developer I would consider using a Methodology for your development.
When you are working alone on a Product you will have to take up several roles to keep an overview.
I would recommend to use the RUP-Process.
It is an agile development approach which can be used be small or bigger groups. Although you are working alone you will profit from this methodology as it will make your Implementation easier. You can adapt the methodology to your needs and decide what is necessary or not for you.
The RUP-Process consitst of 4 Phases.
Inception:
In This Phase you are gathering all Requirements. Which means that you write down what you actually want to do before you start coding. Coding directly will quickly limit your creativity as you will soon encounter errors and forget what you actually want because you have to fix one problem. Take a week or two and write down everything you expect from your application. What it has to deliver or what could be a plus (in the next release for example).
Elaboration:
First you make the architectonial decisions. What db will you use. What language etc. Then you start coding. You are coding arround 80% of your application, leaving the hard stuff out at first. In this Phase you should finish the main parts of the GUI and have bindings to the methods used by the GUI. They do not have to be finished.
Construction
Now you tackle all Programming problems left and all the little errors which you have left out in the Elaboration Phase. It might be that you encouter new requirements. Estimate how long it would take you to add them in this release. You can then decide if you want to finish it or save it for the next inception phase. You should also finish all comments for the methods in your application.
Transition
Now you are Testing the Product before delivery and fix the last errors. Also you should be writing a Documentation of what you have implementet. If you have writting something down in the Inception it should not be to hard for you to write documentation.
When finished you can start another Cycle again starting with the inception.
CONS:
- It might be an overhead having a methodology for only one developer
- You might get annoyed
PROS
- You will have good requirements
- Your Development Process will be faster because you do not have to reconsider your next steps while developing. You have done that in the inception
- You will have a good documentation of what you have built
- You can build a timeline and predict when you will be finished
- You can predict what will be finished with this realease
- If you need help you can give parts to other developers. You are prepared if you need help at somepoint.
At the moment I am the only developer in a Project. With this Methodolgy we can keep track of the process and it helps to coordinate my tasks.
You should also definitly use GIT to secure your process.
UPDATE
Planning of the Architecture/Software itself.
First you should check where you want to use the Software. There are numerous possiblities.
a. Web Applications
b. Mac/Windows
c. Iphone/Android etc.
The first thing you have to decide is where is the Software to be used. If you use it on a Mac or Iphone you could work with Apples new Language Swift
If you work on Windows you could use C#
The Andvantages of these languages are that they are optimized for the System and will deliver you more possibilities then Java or C++.
Now this is only one example. If you need a really fast program, where you can do a lot of optimization on the lower Level you could use C++.
If you want an application that you can theoretically use on both System you could use Java. Although from my experience you will have to do lots of modifactions if you want to publish it on multiple Plattforms.
Your coding skills are also important. It depends on what you can code and what your are willing to learn. Each programming Language is optimized for a porpouse. Python, Javascript, Lisp etc. are also really great languages. It depends on what you need.
First Step
Decide the field of operation --> choose the fitting Language
Second Step
Decide if database is needed.
If you have a simple program you may not need a Database. However databases are a great way to perserve data and offer a lot of functionalities.
For local Applications you could use SQLite. It is a simple Lightweight Database which can be accesed from any language.
If you need more database featueres. Make a research on what the databases offer and which one you need.
Third Step
Start building the Application (a skeleton) and test if your Architecture is durable. You may still change your architecture at this point if you encouter that it is to complex.
I will give you a short example for an app:
You want to build an application that sorts all your Mp3-Files in playlists. Basically a better player then Itunes. But you would want it on multiple Systems.
First Step
- File handling (complexity low)
- Multiple Systems (complexity high)
-> node-webkit
You can build cross plattform Applications with node webkit where you can Access folder etcs. The Corresponding programming language would be Javascript while using HTML5,CSS,Jquery etc.
Second Step
In order to organize the MP3s you will need a database. You will only load the links to the files in your folder so the complexity of entries and the load on the database is low. You can use a SQLite DB here. You could use node-sqlite3 whith your app.
Third Step
Build a scratch application in which you can upload a file or load a file in a folder. See if you setting is working. If yes continue with the building of your app. If no start from Step one and decide whats missing.
I am porting a linux application to the iphone and I would like to know how much re-writing I have to do to make it a multi-threaded application rather than a multi-process application.
Also, if I simply replace the forked code with a call to the functions on another thread I get exec_bad_address at seemingly random places in my flow of execution... Does anyone know why this may be the case?
Thanks!
It is exactly the same effort you would undergo in transitioning your application to a multi-threaded one on a unix platform. Simply replacing the forking code with calls to pthread_create() is - almost always - not enough. For instance, you may need to rewrite all of the code that supports inter-process communication. Say one process forks another, and then the two processes communicate through a pipe. Of course, this will not work anymore. Etc. You get the idea.
By the way, while pthreads are available and perfectly working on iOS, you are strongly encouraged to use other technologies available in iOS. For additional details, please read
Concurrency Programming Guide
in particular the Section called "Migrating Away from Threads".
For details about threading, see
Threading Programming Guide
I am looking at linking a few applications together (all written in different languages like C#, C++, Python) and I am not sure how to go about it.
What I mean by linking? The system I am working on consists of small programs each responsible for a particular processing task. I need to be able to transfer a data set from one application to another easily (the data set in question is not huge, probably a few megabytes) and I also need some form of way to control the current state of the operation (This is where a client-server model rings a bell)
It seems like sockets or maybe SOAP would be a universal solution but just wanted to get some opinions as to what people think about this subject.
Comments/suggestions will be appreciated, thanks!
I personally take a liking towards ØMQ. It's a library that has a familiar BSD-sockets-like interface for passing messages, but you'll find it implements interesting patterns for distributing tasks.
It sounds like you want to arrange several processes in a pipeline. ØMQ allows you to do that using push and poll sockets. (And afterwards, you'll find it's even possible to scale up across multiple processes and machines with little effort.) Take a look at the guide to get started, and the zmq_socket(3) manpage specifically for how push and pull works.
Bindings are available for all the languages you mention.
As for the contents of the message, ØMQ doesn't concern itself with that, they are just blocks of raw data. You can use any format that suits you, such as JSON, or perhaps Protocol Buffers.
What I'm not sure about is the ‘controlling state’ you mention. Are you interested in, for example, cancelling a job halfway through?
For C# to C# you can use Windows Communication Foundation. You may be able to use it with Python and C++ as well.
You may also want to checkout named pipes.
I would think about moving to a model where you eliminate the issue by having centralized data that all of the applications look at. Keep "one source of the truth" so to speak.
Most outside software has trouble linking against C++ code, due to the name-mangling algorithm it uses for its symbols. For that reason, when interfacing with programs written in other languages, it is often best to declare wrappers to things as extern "C" or inside an extern "C" { block.
I need to be able to transfer a data set from one application to another easily (the data set in question is not huge, probably a few megabytes)
Use the file system.
and I also need some form of way to control the current state of the operation
Again, use the file system. A "current_state.json" file with a JSON serialized object is perfect for multiple languages to work with.
It seems like sockets or maybe SOAP would be a universal solution.
Perhaps. But it's overkill for this kind of thing. Your OS already has all the facilities you need. Just use the file system. It's very simple and very reliable.
There are many ways to do interprocess communication. As you said, sockets may be a universal solution. SOAP, i think, is somewhat an overkill. You may also use mailslots. I wrote C++ application using it a couple of years ago. Named pipes could be also a solution, but if you are coding on Windows, it may be difficult.
In my opinion:
Sockets
Mailslots
Are the best candidates.
i have never done embedded (i dont know if thats what you call this) programming and know nothing about it. my question:
is it possible to have two devices sharing a wireless connection (no internet, just between themselves, perhaps bluetooth, but i dont know what ever is best) ?
is it possible to have one editing a file and the other person editing the same file and they can see changes in real time? sort of like google docs?
does this exist already?
what can i do to get started regarding this kind of programming?
to clarify:
i want two people with iphones or any other hand held device, to be able to edit a text file at the same time and see each other's changes in real-time. how do i do this?
There are a bunch of slightly strange assumptions hidden in your questions. I'll try to unpick them as best as I can.
You've used "embedded" programming in a strange way. Usually this would suggest some kind of low-power devices used in settings without direct user interaction in some sense (e.g. factory controllers, refrigerator controllers, sensor nodes), performing a very specific task, but you've gone on to talk bout people editing files. What exactly would be the user interface here? What would make this embedded programming? I think you need to describe an application before any advice can be offered.
If you actually mean embedded devices, then whether they can connect wirelessly to one another is going to depend on the nature of the device. Similarly, the protocol/technologies involved will depend on the device. Embedded programming tends to be very much device-specific. There certainly exist wireless sensor nodes, for example, that incorporate small radio transceivers for serial comms.
Google docs already exists. Without a clearer problem description it's difficult to say whether what you want exists already or not.
I think you should really figure out exactly what kind of programming it is that you want to do before we can offer points as to how to best get started with it. Maybe look up a definition of "embedded programming" and see how this relates to your goals such that you can reformulate your questions a little more clearly.
I'm not sure how "real time" would fit into this scenario either. This term is used and abused in many ways. Things are only ever real-time with respect to some constraint, usually defined in terms of the application.
(Note: This might have been more appropriate as a comment, but I felt there was too much to respond to in order to sum up within character limits, and I hope correcting some of the confusion constitutes something of an answer, given the limitations of the question).
Two devices can share a connection like this. It's done all the time. There are many many protocols for this. Weather or not it is wired or wireless or uses the Internet doesn't really matter for 90% of this.
This is sort of doable, but not really. You really have a race condition when two people are editing at the same time. This is generally avoidable by locking out small parts of the document at from all but one editor at a time (like only one person being able to edit one cell of a spreadsheet at a time), but this has problems too (like of the one active editor is taking way too long -- this is a problem seen in many source version control systems too).
1 already exists in many many forms. 2 sort of exists in many forms, but the problems I mentioned are impossible to completely overcome.
The way you asked this question leads me to believe that you are very far from being able to do this. In addition, you didn't tell us anything about what you do know how to do. Can you write a simple text editor for an iPhone (or anything else)? Simple text editors from scratch that aren't crappy aren't easy to write.
What you need to do, if you really want to do this, is to come up with a protocol for the two (or more) devices to talk to each other in. To do this it is probably best if you figure out what type of communication is available between the devices and which of those you will use and what features it does not provide that you will need on top.
You could try to send patches of the file (or something similar) between the two devices as edits are made, but then you'll have to decide what to do in the event of a collision (edits near the same place).
Alternately you could have the two devices exchange permission to make edits (like in token ring networks).
You still have a problem if the two devices lose communication with each other during the editing of the file, though. With the token ring type setup you stand the possibility of losing the token and neither being able to automatically recover easily. Whatever you do you end up with the problem of the two ending up with different ideas of the file's contents.
"iphones or any other hand held device" - the technology stack to do that doesn't exist today. You have to co-ordinate between multiple languages and systems. (Okay, maybe you want to write that software, but it's a huge undertaking).
Your best bet would be to create a web page that all of the mobile browsers can work on and save a text file from.
Of course it's possible. Bluetooth does this. Wi-Fi does this if you join an ad-hoc network.
Of course it's possible. Just run the Google Docs server on one of the devices.
It might.
Way too vague.
Are there any guidelines on pitfalls to avoid while developing iPhone applications?
Sure, thousands. The same is true for any software development. Unfortunately, the easiest way to enumerate them is to write them down on a sheet of paper while waiting for a friendly soul to release you from the one you just fell into.
However:
Don't try to reinvent the wheel. The iPhone API is very complete -- you just have to LOOK for the facility you need. Things are NOT always implemented the way you would expect. Read the guides, carefully. Look at the tutorials and analyze how they work. (Try changing a line here or there in the tutorial to see what difference the change makes.) The single biggest mistake I have made in 1 year of iPhone development is not trying hard enough to find the iPhone way of doing something.
Don't ignore memory management; master it early and often. Use the Object Allocation and Leaks tools in Instruments to check for memory leaks frequently. I'd recommend checking after you complete each feature or view; more often than that if you keep finding bugs. Eventually you may understand it so well you can stop doing this.
Don't just use the default build settings. Play around with them to understand what they do. Figure out certification and distribution. GET INTO THE DEVELOPER PROGRAM QUICKLY -- it can take a while to push through that pipeline. [ AND when you get that notification that you need to renew, get it on instantly -- there have been problems with that process. ]
Don't neglect to read the Human Interface Guidelines (HIG) carefully. If they say not to do something -- DON'T DO IT. Apple will reject applications that misuse their iconography.
Don't stint on marketing. Yes, the App Store puts your app in front of millions of people... In theory. But the odds of getting front-paged are slim. There are a lot of great apps on the App Store that haven't sold much because no one knows about them.
Don't rest on your laurels. If a new technology comes out, find out if it makes your job easier; if it does, take the time to learn it. Personal example: I'm just now trying to switch from SQLite-based data management to Core Data, because I was in a hurry at the time I started my most recent project; now I wish I had slowed down and thought about it.
Don't go into your design thinking (for example) "How do I implement my concept with a table view?" It's true that table views are natural for many informational and utility applications, but don't be constrained. Instead, think about what users will want to be able to do, how you can make it easier for them -- put things together that will be used together, etc. If you've never explored the concept of Use Cases, read up on them.
Don't hesitate to build composite views. Many of the questions I have seen here on Stack Overflow have to do with putting a toolbar at the top of a table, or having an image in the background of a text field. I understand the desire to do things the easy way, and as I state in #1 above, if there is an easy way, use it. But in many cases the solution is just to layer a couple of views with appropriate placement and transparency.
Think about what might be Apple-approved from the start.
App Rejected is one of several useful sites to help understand Apple's mostly undocumented standards. (One more.) (A previous question on app store rejection reasons.)
A few quick examples:
Using a UIWebView can get your app a 17+ rating.
Coding with an undocumented/private API = rejected
Version number < 1.0 might= rejected
Not enough feedback about network success/fail = rejected
Too much network use = rejected
Clearly limited free version vs full version = rejected
The word 'iPhone' in the app name = rejected
The above links contain many more examples, and more details about those examples.
Don't neglect the programming guides. While the documentation is quite extensive, the programming guides contains a veritable trove of useful tips and "insider" information that simply cannot be gleaned from reading method definitions. I spend just as much time reading the guides for a technology (say, Core Data) as I do actually implementing it.
Don't assume you know what a method does. If you have any degree of doubt about the functionality of a method, it is well worth your time to go look it up in the documentation to verify.
Wonderful examples from #Amagrammer above.
I would love to add that the first place to start is iPhone development is Photoshop. This is still the best advice I can give to anyone who is starting out. I now use OmniGraffle because it has awesome stencil templates.
What I find is that even for super simple app's, draw up your prototype and look for usability issues and work flow issues. It is 100x quicker to redraw your app than re-code it. I have fallen into this trap numerous times and now actually draw up some pretty simple functionality to see what it will look and feel like.
This advice will save you 10s maybe even 100s of hours in hopefully getting your app right first time and getting you to think through what the issues are. Throwing away code sucks and I have done it not because the code was bad but because it made the usability or solution worse. I think the best of us end up throwing code away and prototyping your design definitely will help in having to RTFM for something you did not have to build in the first place.
If you don't have an great designer, and can't do great design by yourself, then don't even start iPhone app development. This rule only applies if you want/need to make money with your apps.