Understanding UIKit, Storyboards and underlying frameworks - ios

I’ve started with the App Development with Swift a few weeks ago. I liked it because it was a mix of Swift and Xcode and UIKit.
I studied C and C++ in uni and I also had an intercourse with C# that gave me some kind of an idea of an interface builder. In no ways I dived deep into it but it was C code, and it was quite clear how to edit and do stuff in code.
The problem is, the book mentioned above does not explain anything about UIKit or Storyboards in depth. But more like at all. You are editing classes, you are writing functions that magically get called at certain events, but most of this is invisible. It just works (but it’s not a positive thing here unfortunately). I have no idea how to do these things programatically.
UIKit is complex and I find it a quite confusing. It seems to go against the basic coding that I did before in C (terminal stuff). My minimal C# experience gives me a few ideas but that’s just not enough.
Is there any good place where I can start off? Swift is fine, so I’m not really interested in that.

First and foremost, if you're serious with iOS development, I strongly suggest you get a hold of this book, it's really worth the money.
http://shop.oreilly.com/product/0636920055211.do
And to your questions:
UIKit is a built-in framework in iOS, in which important UI elements (Views and Controls) are implemented.
XCode is an IDE just like Eclipse and Visual Studio.
A storyboard itself is where you implement the the UI of your app (which can also be done via coding). Storyboards offer many powerful tools for you to conveniently design your UI visually, and see how the screens in your app looks like.

Related

How safe it is to use third party FRP frameworks for long running project knowing that swift is constantly being changed?

Background:
I need to start working on project which we are hoping to maintain it for long time (Basically reusable components which will be reused in multiple projects). I was exploring the Reactive Programming and the benefits Reactive Programming brings to the table is way to high to ignore it.
I started exploring various FRP frameworks available and RxSwift, ReactiveCocoa were few such examples. But looking at the community support and swift implementation, RxSwift was obviously the choice.
Now RxSwift4 came with some breaking changes as RxSwift3 wasn't compatible with Swift4. Now community did a great job to bridge the changes smooth, though but things like DelegateProxy implemented in RxSwift3 started breaking in RxSwift4. So for those who used RxSwift3 it wasn't just a pod update but involved loads of changes as well. On following the RxSwift Git hub issue realized that its because of Swift4 changes which lead to this break.
Question:
Now its a very common risk that we take on using all third party frameworks, but with most of the frameworks I used, if broke they would have break a feature or two in app but if I write a complete app in RxSwift and future updates break, finding a replaceable library and replacing it would be a enormous job.
Here is why?
For example, if you use Alamofire, usually you will have your own Network layer in app which would expose certain API to app and app quite frankly wont worry about the library used under the hood. So replacing it is quite a easy task. But with RxSwift all asynchronous tools like delegates, blocks,notifications are already wrapped in RxSwift components like Observables,Subjects,Units etc to which we cant write a wrapper of our own and if Current RxSwift version breaks in future update we will be left with no other solution than to literally fix them one by one, as replacing library would mean complete re writing of project.
I know its a kind of opinion based question, but the problem is there is no much guiding opinion on web for the same. I would really appreciate, if somebody who used FRP frameworks in their project post the best practice to use them so that dependency on framework will be minimal and allow us to shift to new FRP framework easily in future.
EDIT:
The mention of Alamofire above is just to show how easy it is to wrap other frameworks that we use in our app only and has nothing to do with RxSwift in itself. So please don't get carried away by that :)
My short opinion-based answer is that it is safe enough starting from Swift3 because backwards-compatibility is guaranteed starting from Swift3 onwards. I use RxSwift and a bunch of derived frameworks (RxCoreData, RxCloudKit, RxGesture, RxCoreMotion and RaspSwift) extensively for about a year now, never encountered anything particularly troublesome. But then again, you mentioned some frameworks which I did not use that gave compatibility troubles. So apparently there might be unpleasant surprises, which are usually fixed quick enough by the open-source community.

Merging Objective-C project to Swift; what's the best method?

I want to migrate our large Objective-C-based iOS project to Swift. So what's the best way: Import Swift files into Objective-C, or import the Objective-C project into a fresh new Swift project? What will be the fastest ?
Thanks
After time I spent of the project migration to the Swift I can say that it is no silver bullet in this question. It is really depending on the flow that is set-app in the team that you are working.
From my point of view and experience you should take existing project and start to write all new logic using Swift and in parallel try to rewrite business lawyers of the application in the modern way. For example network layer, database layer. In this way you reduce regression of the application and receive controlled migration flow.
Pros:
New logic will be in Swift.
Step by step migration will balance
regression.
Suport of legacy code that impossible to rewrite to Swift
Writing code in Swift way (Protocols, Function, Generics, Structures)
Cons:
Time
Regression of the app
Quite big rewriting of the code.
If you are starting a fresh project with the aim to only use Swift in the future, then I would create a new Swift project and then link to your Objective-C framework. This is what we did where I work, and slowly over time we have been deleting from the Objective-C project anything that is not being used. This may not be quicker than importing everything into the same project, but will give your code some separation from the old Objective-C code.
It's a very complex question and the answer is: Depends...
I think there are a few questions to make before answer yours:
Is your project "open", your team is developing new features on the same code base? or has a solid and reliable code base and just a little changes?
Can your company afford a "NEW VERSION" entirely made in Swift with new engineering?
Basically, make a big refactor (as language migration) involves a re-engineering job too, most things will not work if you just transcript the code base and if you do so, you are losing all the Swift benefits and there is no Win situation to change your code.
In my point of view, creating a new project is just a good thing to do if you will make a new version of your app. Is cleaner, is better, but like I've said there will be a lot of job and re-engineering.
Otherwise, just embed Swift code into an Objective-C running app, will cause a lot of trouble and confusion. But is faster and you can continue with new features and implementing improvements on your app.
So, here is my 2 cents to your problem:
I would recommend slow code conversion or rather refactoring to Swift if required for new code parts.
Furthermore, if the converted code is currently being used in other side projects (feature branches etc.) you could not ensure that it would still work accordingly.
I hope you got unit tests in place, because those could make life easiert. Anyway, consider the aspect of regression testing of your application's features. Libraries you use, would now have to be frameworks (some Libraries might not compile as Framework, be aware of that).
IF you really want to convert the code base, I would do this hirarchically.
Consider an entire Application Layer and within this layer
specific classes.
Start writing tests for those classes (you can do that in Swift, too), Unit Test, Integration Test, UI Tests
Convert the class to a swift class (be aware that some logic might change and other functions would be affected, too)
Implement bridging header (if necessary) that you can use as Application Layer interface to the other interfaces - this would even improve your understanding of the different code parts play together. If you notice some weird declarations. Stuff being public, too much random accesses fro different classes or something. Don't touch that yet. In fact, note that down
Perform extensive tests of your small change
Start over again with the next class
If all classes have finished on your current Application Layer and you broke nothing. Good job. Now have a look for your notes.
Continue with the next layer.
In Short: I would only convert those parts to Swift that need to be changed anyway (refactoring, new features, bugs, whatever). If the code was working, and you don't see another reason than "well, now it is Swift", I would only take the conversion into account, if I really had time for that, else you might break working code or even the architecture that was setup, which differs for Swift and Objective-C in some ways.
If you really feel like you are the man for this: I would start to write tests ;-)
Unit-, Integration and UI Tests. This will help you with your CURRENT code base, but also with your future code base, whether is in Objective-C or Swift.
And it is a great help for converting the code into Swift.
I think the best way is to import the Objective-C project into a fresh new Swift. Because you can use objective c to swift converter. It saves thousands of work hours.

Using interface builder is really a bad practice? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I started developing for ios in a new company.
Here they taught me to never use iterface-builder, saying it's hard to maintenance the code and it have a few limitations.
Using interface build for java application in netbeans i see a lot of "bad code" but i don't see it using IB, besides i see a lot of IB codes on the internet and only a few codes without it.
So for a large where no one is a beginner on ios development is a bad pratice use IB?
(Let me mention in advance that I have strong objection against using Interface Builder, for a number of reasons I will explain)
Here they taught me to never use Interface Builder, saying it's hard to maintain the code and it has a few limitations.
This is only partially true. The principal reason I don't like Interface Builder and Xcode in general is that a lot of beginner programmers think that it is the only way for developing iOS/OS X apps. They have never heard of gcc and clang, they don't know what the compiler and linker error messages mean, they can't use make, and they have no idea about what the difference between the Objective-C language, the Cocoa (Touch) APIs, the IDE and the compiler is.
After all, they start using Interface Builder and Xcode with all of its quirky and sometimes strange/illogical features (and bugs as well), but when they're in the need of developing something non-obvious, they don't even realize there is a method for, for example, creating views and view controllers programmatically (yes, I've seen this very question on StackOverflow).
So, when abused (or rather, used too early), Interface Builder and all of the "convenient" features lead to programmers learning bad concepts and missing some important pieces of practice and experience.
However, if you're a senior developer, who has all the necessary skills, and you feel you could write an entire application from scratch, using just a simple text editor and a Makefile, then you are by all means permitted to use IB, and even encouraged to do so if you feel that's more comfortable than hammering out code.
So, to sum up:
Using interface builder is really a bad practice?
No. Rather abusing it and not making the effort to learn the programmatic approach to UI stuff is bad practice.
Post scriptum: I have quite a lot of experience with iOS development, but I still find Interface Builder rather inconvenient and inconsistent. I generally use code for everything. But that seems to be my personal preference. One advantage is, however, that if one creates everything by code, then another programmer without access to these Apple-specific tools will be able to contribute to the project as well. This is a point where the "it's hard to maintain" part comes true...
For example, until I didn't have enough money for a Mac, I used Linux for developing iOS apps (yes, that is actually possible). I couldn't use IB and Xcode, yet I have done loads of applications and tweaks (for jailbroken iOS, of course), and that was just fine.
Post scriptum #2: another reason for avoiding the use of IB could be the need for dynamic UIs. If you heavily rely on animations, custom UI elements, etc., it's hard to do everything in Interface Builder. Last summer, I had to rewrite a login screen of an application, and honestly, I don't know how I could have realize our designer's ideas if I had had to use Interface Builder. The UI/UX was so dynamic and it had so many ways to change that it was absolutely necessary to have fine control over each and every pixel. And that's something that code is better at than IB.
I strongly disagree with the idea that IB is a bad practice. Interface Builder has the following advantages over code:
when working with complex (and even simple) graphical interfaces, IB cuts the code down to a mere fraction - for example, simply creating a button in IB takes a few seconds, whereas in code, that translates to dozens of lines, especially if the button is to be styled
using autoresizing masks for supporting multiple resolutions and devices is a breeze - this is important as Apple is now pushing towards resolution-independent apps
changing/tweaking properties of views is a matter of a few clicks rather than lines of code, especially if working with images
However, there is one disadvantage (that comes to my mind):
it can hard to pinpoint what might be causing a graphical problem, since it will be hidden away in in the IB file than in the code
Absolutely not. Interface Builder is a really powerful way of creating UI really quickly. Especially with Storyboards it allows you to make functional apps with very little code.
The issue of it "creating bad code" is rubbish as the IB doesn't create any code. The files it creates are essentially XML files that complement the code that you write.
Most of the apps I've developed have been mostly started on IB.
Obviously, you can't do the FUNCTIONAL stuff of your app. I.e. you can't tell a button exactly what to do. But you can point it to a function that you have written and get a working button with almost no code.
Most of the UI in iPhoto on iPad and iPhone is written in Interface Builder.
Much has been said, but I am still going to give my 2 cents for this discussion...
Until some point I agree with H2CO3, it's better to understand what's going under the hood, than keep using shortcuts to achieve something. That works most of the time, the thing, and that's where I strongly disagree with H2CO3, is the following:
Most of the people that use a technology (C#, Java, HTML, iOS, etc), they use it because their Company needs them to use it, because someone else is actually going to pay you to work with that. And not because you actually woke up in the middle of the night and suddenly had the urge to learn C.
If someone asks you tomorrow to create an iOS App and you never developed for iOS before, I truly doubt you are going to create an App from scratch without using XIB's or Storyboards (Which I hate btw).
What H2CO3 proposes is a utopia... Where you really understand what is going on beneath, but because you are such a "leet", you are able to use shortcuts, like XIBs. Well, things don't work that way, and sooner or later you will have to do some shitty thing to deliver something on the next morning.
I prefer, and that's personal perspective, to use a XIB, than to use the first 3rd party library that comes in front of me. And I think that's more reasonable than doing an interface by hand. I prefer to understand the code, and do it by myself, than using for instance a library to help me download/upload stuff.
For wrapping this up, my advise to the person that asked this is:
Try to understand why things are done the way they are. Above all, try to be a better programmer in each new project that you face. If something new comes up (new iOS version) spend a day or two to see what's new, and what could you use. XIB's are perfectly fine to be used, but spend some time creating UIView's by hand, so you can see all the flexibility they give you. And above all, run away from Storyboards (^^)
P.S: A senior developer it's not just a guy that has a "better Kung fu than you".. It's more than that.

Why is using MonoTouch for iPhone development not recommended? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
We want to develop an application for iOS and Android smartphones. We are mainly using Microsoft technologies for developing our applications. We thought that if we would use MonoTouch and Mono for Android we would only have to maintain one code base with only a different UI layer for each device.
Because currently nobody in our small team ever developed a smartphone application and we need it quickly we want to outsource it. We asked other companies whether they perfer MonoTouch or Objective C for iPhone development. Most of them said, that the would choose Objective C. They said that Objective C offers more functionality and possibilities, it's faster and for MonoTouch there is a chance that Apple will not support it anymore in the future. Is all of that true or are there other reasons to prefer Objective C? I know there are other threads like this around, but they did not answer my questions, especially the one regarding Apple's support for MonoTouch.
applications. We thought that if we would use MonoTouch and Mono for
Android we would only have to maintain one code base with only a
different UI layer for each device.
this is a possibility IF you structure your app right. If not: no.
If you use Java+ObjC+C# (for WP7 / Win8 metro etc) then this is not an option AT ALL
Because currently nobody in our
small team ever developed a smartphone application and we need it
quickly we want to outsource it. We asked other companies whether they
perfer MonoTouch or Objective C for iPhone development. Most of them
said, that the would choose Objective C.
If you are outsourcing it, you should dictate what you want it written in, surely? If you need to support it in-house, and you only have C# skills, then MonoTouch etc makes more sense for you, the people paying the bills!
They said that Objective C
offers more functionality and possibilities,
FUD, and also incorrect. Monotouch has the full API available. If it's not there, as Xamarin to bind it (which they have done often before)
it's faster
I'd love to see the benchmark. Yes, technically, it can be faster in some circumstances, but in general use, MonoTouch the same or quicker.
Programmer error is a more common cause of iOS app performance problems. eg not getting things off the UI thread (which is easier to do in MonoTouch than in ObjC, tho blocks have helped that a lot), or taking too long to get out of FinishedLaunching (the "main" method, if you will, tho it's not really...)
Garbage collection and things like linq, xml/json parsing, generics and collections are also hugely valuable, and very quick.
and for
MonoTouch there is a chance that Apple will not support it anymore in
the future.
yes, there is a chance. There is also a chance that Tim Cook will run off with Apple's billions and buy all of Hawaii (rather than Larry Ellison's "I'll just have this island" purchase). But the chances are now rather slim.
Is all of that true or are there other reasons to prefer
Objective C? I know there are other threads like this around, but they
did not answer my questions, especially the one regarding Apple's
support for MonoTouch.
Apple doesn't support MonoTouch. Xamarin does, and they do it exceptionally well. Apple doesn't support anything except XCode, which is their product.
Apple DOES allow MonoTouch apps (there are lots). Another way to look at it: usually, 95% of the top 100 games are written using Unity3D, which is based on the same techniques (ahead-of-time compilation of C# code and embedding a cutdown version of the Mono/.NET framework).
There ARE reasons to prefer ObjC which would be:
You already know ObjC and CocoaTouch and like it.
Your team already knows ObjC and CocoaTouch or you can easily hire people who do (note: currently, as far as I know, iOS developers are CRAZY expensive to hire, if you can get them)
You need to use the beta's the day they come out. Keep in mind that you can use the current MonoTouch and deploy to your iOS[REDACTED] device with the beta on it. You just can't use the new stuff in iOS6 YET (Xamarin said "around 2 weeks" which should be about now...). Also keep in mind that you can not deploy an app to the store which is built with the beta SDK, even if you don't use any of the stuff in it. You can't even mention iOS[REDACTED] in your product description (I've tried)
you love [squareBrackets andTheOccasional:#"strange syntax things"];
Now, will building a cross platform, shared code app be an easy undertaking? HELL NO. It's a very complex piece of development for a non-trivial application. But thats the fun part of software development: if it was easy, it'd be boring! Grab Greg Shackles book ( http://www.amazon.com/dp/1449320236 ) to get an idea of whats needed for iOS+WinPhone+Android style development.
My hunch is that the companies you talked to simply are used to using Objective-C. That's where their skills lie, and that's the biggest reason why they would prefer not to deviate from their path. The other reasons can be argued both ways.
It's true that no one can predict what Apple will do, but there's a very small likelihood that Apple will ban third-party toolkits & APIs like they did in the summer of 2010. That was only a short period of time, and they completely reversed that decision. Their current focus is on making app development easier, which means keeping the field open to alternative development methods. I think MonoTouch is safe.
As for speed, C# generally produces very fast executables. They may not be quite as fast as Objective-C, but I doubt you'd notice a difference. I remember seeing a website somewhere that showed C# outperforming C/C++ in some tests, but that was in the .NET environment, not Mono... and unfortunately I can't find the reference anymore. I'll keep looking. But the bottom line on speed is that C# speeds are very good. It's not like BASIC vs C. More like Java/JIT vs C.
C# gives you many, many(!) advantages over Objective-C, and they have been enumerated in other Stack Overflow answers, so I won't repeat them here. You can find them easily enough.
I'm an obvious fan of MonoTouch, but I do have to say one thing: I think it's a mistake for companies to think that because they are fluent in C#/.NET that they will easily be able to develop and/or maintain iOS apps using MonoTouch. It's just not true, because MonoTouch is basically a C# layer over the CocoaTouch API, meaning that you have to learn the Apple way of doing things. You have app delegates and view controllers and all the UIKit stuff. There's a real learning curve there. But if you're fluent in C#, MonoTouch will be a huge help.
UPDATE:
I found the article on C# speed: Head-to-head benchmark: C++ vs .NET
I have actually used MonoTouch for every app I've ever developed. Performance has never been an issue, and I can't imagine how bad for me it would have been using Objective-C. I've had 2 top 10 apps in the US app store: "Draw A Stickman" and "Draw A Stickman: Episode 2" (don't worry we are working on more).
If you know C# and .Net your gains in productivity are going to be massive compared to what would happen trying to learn Objective-C. I was a C# .Net developer (Windows only) prior to iOS development and the transition to MonoTouch is great.
If you like Linq, parsing XML in fewer than 100 lines, garbage collection, generics, simple multi-threading, and no weird square brackets, MonoTouch is for you.
I use both Objective-C and c# (MonoTouch & Droid), and I really like both. When I'm coding in c#, there are plenty of features such as Linq which I'd love in Obj-C, & when I'm coding in Obj-C there are plenty of things I'd love to have in c#, but I adapt to whatever I'm coding in quickly enough. Re performance, I've detected no difference at all, even for fairly graphic-intensive stuff, so I wouldn't use that as a reason not to use c#.
I think it's ultimately down to what you're comfortable coding in, though of course with a well designed cross-platform project, you CAN have fully cross-platform core code if you use Mono, and you'll only have to do the UI stuff in a platform-specific way - when it comes to this obviously you'll need to know the native stuff to get your UIs working in a way which is appropriate to the platform and familiar to its users.
We have a line of business app that uses MS SQL as a data store, and has WinForms and web UI's. It integrates with our windows mobile 6.5 and tablet apps with web services. All c#.
We've fully committed to MonoTouch after some experiments in Objective-C and HTML-5 (we had working prototypes): we get to re-use our business logic, and we're comfortable developing new code in c#.
Our business logic is constantly being enhanced, and these enhancements are immediately visible to the mobile app - without having to replicate the logic in Objective-C or C++.
Our main issue is finding a c# programmer who's comfortable with the iPhone and iPad UI's.
MonoTouch is stable and we've encountered no limitations (we're binding to the same iOS API that Objective-C binds to). During our learning curve, we've had question, bumped into bugs and have had some misunderstandings - but the support from Xamarin is superb.
Performance has been a non-issue - our app is snappy even though it's doing a lot behind the scenes.
No body can tell you for sure what will apple support and what it will not support in the future, however apple had some issues with mono in the past, and since history tends to repeat itself, then it may be a possibility of that to happen again
Having said that, always go with the native application development SDKS and environments, it will be more flexible, and it will be updated real time, and performance will always be better in the native

What are the advantages of iOS 5.0 storyboarding over traditional UI layout?

I am a total beginner in iOS development. However, I've done Java, PHP and Javascript at work for severals years, so I am pretty experienced with OOP and design patterns.
Xcode 4.2 adds the new storyboarding capability for laying out interfaces in iOS 5.0. Is storyboarding simply a wizard for beginner developers or does it have advantages for more experienced developers as well?
My coworkers and I (both beginners in iOS development) are debating whether one should learn and program iOS using traditional NIBs vs storyboards. What are the advantages that storyboarding provides over previous ways of laying out iOS interfaces? Are there disadvantages to this approach?
Learn the old way in case you have to do both (or read some legacy code). This goes for Arc too; I shudder to think of new Cocoa/Cocoa Touch developers not understanding the old managed memory model.
I think the automated and convenience methods will always cover the "common" cases, and that story-boarding is an example of that. A convenience which greatly simplifies and accelerates the development process. However, there will always be cases where these methods do not provide you with all you need in a given, unusual situation. Just like using the UI elements does not stop developers from going under the hood with core graphics, core audio and so on when they need to. It is definitely, I think, a part of the future of iOS development, but only being aware of that part would be a handicap. So would not being aware of it.
I, personally, dislike automated tools. I have no idea what happens below, what sort of surplus code is inserted, the style of code is not mine and hence I need to work on another person's code. I'm the one that needs to support it for rest of time, not whatever automated tool I may have used.
It is all the tedious abstractions that will help you understand what is going on, especially when you are new to a field.
I'm personally like the traditional nib file approach, where I have more control over its behavior programatically and not having to hack the stroyboard backward to get things done. And of cause, if you have few developer working in a project, it's always good that you don't have to spend time merging changes (since you have several nib file compare to storyboard file)
storyboard files seem to be more readable than xibs.
both are xml files but the xibs seem to have unnecessary baggage and complexity.
I have compiled a list of about 15 reasons against using Storyboards: When to use Storyboard and when to use XIBs
Also, here's a tool that takes some of the pain away: http://github.com/jfahrenkrug/StoryboardLint

Resources