I'd like to create components which have a similar structure (all of them having a controller class, a XIB file and language resources). I've figured I could use bundles for this purpose. However, it seems there are some limitations on iOS (for example you cannot use loadable bundles which pretty much correspond to what I'd like to do). For me this would be important for better organisation/packaging of code and better reusability provided by such components.
Does anyone have a good pointer to an arcticle, etc dealing with similar issues?
If you can wait for iOS8 this is made easier as you can now use Frameworks, which are an easier way of bundling code and resources.
These are still tied to the app at build time, so you can't use them for plug-ins at run time, but it should make sharing code and resources between projects simpler.
Related
I am new to iOS development, so please excuse me in case my question sounds trivial.
I am planning to introduce MVP or VIPER pattern. I am from Web background and in web application we used to follow different layers/dlls (for model, view, common etc.). Does it make sense to follow the same layered approach (frameworks in this case) in iOS and or it will be overkill? I have not come across any sample project (based on MVP) which create different framework for model, View and Presenters? It would be great if someone can share any sample project (based on MVP) which we can use as a starter project.
Thanks In Advance
In iOS, we generally use MVC - Model/View/Controller. So, if you're looking for the analog in the iOS world, that's it. If you're saying that you've really dug into MVC and there's something that you find deeply unsatisfying, and therefore want to introduce a different pattern, then that's a different question.
So, no, the sort of logical separation of responsibilities that you see in approaches like MVC is not overkill. In fact, the division of "view" and "controller" classes are fairly central to everything we do (e.g. UIView subclasses, UIViewController subclasses, etc.), so the only thing you really have to do is design appropriate "model" classes and you're off to the races.
But, in answer to your question, you don't generally use separate framework targets for the model, the views, and the controllers. That probably would be overkill. Usually you can keep track of everything through through judicious use of Xcode groups/folders within your project. We generally only pull stuff into frameworks for more technical or logistical reasons (live views, app extensions, sharing code between multiple apps, etc. ... see WWDC 2015 Building Modern Frameworks for discussions of when you'd generally use frameworks).
But to the question of MVC vs MVP or VIPER (or MVVM or whatever). I'd suggest that you simply embrace the shared spirit of all of these patterns (namely the separation of responsibilities) and apply it to your iOS MVC code. Once you've got some iOS experience under your belt, you can then re-evaluate this pattern question.
If you're starting with iOS developement and is looking for a good architecture, go with VIPER. It's not at all an overkill as long as you:
1 - Automate VIPER files generation
2 - Automate VIPER modules initialization
To accomplish both requirements above, use this Xcode plugin (https://github.com/natangr/ViperTemplate) to generate and intialize VIPER files automatically. It works like charm!
And read this post https://www.ckl.io/blog/best-practices-viper-architecture to get more tips on how to automate things when using VIPER.
I do use it, even for very small projects (160h of development)
I've been browsing the DeHL repository on GoogleCode, and it looks really good to me.
Many interesting features that make basic programming tasks easier; Some neat things that are in the DotNet FCL, but are missing from the Delphi RTL can be found in this library;
Coded in a modern way, making good use of new language features;
Each class, record type, member function and parameter is documented in such a way that it'll show in the code completion of the Delphi IDE;
Well-organized and clean code;
Plenty of unit tests;
Open source and Free;
Basically, it looks like this library should've been included with Delphi, as part of the RTL.
One major drawback: The project has been discontinued. :-(
Now my question is:
Would it be safe to rely on this library for future projects, and use it as a base framework to build upon?
Basically I'd like to hear from somebody who's actually used this library whether or not it's worth it to invest time in getting to know this library, and why.
IIRC the project was discontinued because it was an over-engineered first attempt and a lot of its features turned out really messy and bloated. You should look at Alex Ciobanu's second attempt, which is simply called Collections. It contains most of the interesting features from DeHL, but leaner.
Be careful, though. It still makes heavy use of generics, which will make your binary size really big if you use it a lot, because the compiler team hasn't implemented a way to collapse duplicate code yet.
Quite a broad question. I'm looking to refactor an existing game app so that we have a base framework for games, which are extended with some kind of modular plugin architecture. So we have:
GameCore - lots of base classes, etc.
GameBundle A/B/C... - bundles with lots of subclasses of those in the core, along with lots of resources
The game won't function at all without a concrete bundle which implements the game itself. In theory it would also be possible to break down these bundles further and mix and match. This is a very appealing design.
Using NSBundle seems to be the neatest solution, but I'm hitting some snags: The code in the GameBundle must be linked with the GameCore or it won't compile, but then when the GameCore code is loaded from the NSBundle, you get duplicates of all the core classes. This suggests that I'm way off the mark with how I'm approaching this!
This could easily be implemented with static libs, but then it's not possible to easily include resources...
So, could anyone suggest a workable architecture that would do as I wish? To summarise;
Abstract game core
Indeterminate number of GameBundles added to the target, which are (ideally) loaded dynamically at runtime.
Hope someone can help!
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
I have built mini widgets that consist of a model, a controller a couple of stylesheets and a couple of lines of javascript. Whenever it turns out that I need something like that in the next app I am building, i have to do some copypasta from the app where I had built them. Needless to say, that is not fun.
So I've heard about component frameworks like Cells, Apotomo and Parts, which promise to alleviate this chore, but I couldn't find any discussion around them or any other significant community activity, usage stats, and so on, to indicate their adoption. Except for a few blogposts, the community is oddly silent about component frameworks. That makes me wonder: are they a good idea and if they are not, why not?
Reusing code from multiple projects is in general a good idea. It reduces the need to maintain multiple different sets of code and makes it easier to implement functionality quickly.
I would create a repo specifically for those components and simply pull it into your codebase as a plugin. As for how to structure this component its identical to any other gem available on github , providing you namespace items correctly you can port it easily between applications without issue.
The plugin and gem paradigms for Ruby/Rails are well established. They are probably the best routes for re-use of components
Cells usage stats (since September 2010): https://rubygems.org/gems/cells