I got a question that i'm trying to figure out.
How can i set 2 different Subclasses in 1 UITextField?
I have installed a library ShowPassword(via cocoapod) and currently i'm using it so users can see the password that they are typing.
But i have also installed another library that makes an awesome UITextField (also via cocoapods)
https://github.com/raulriera/TextFieldEffects
And with this library i can insert Subclass Hoshi for example (which i have done in username text field)
How can i import both of them in password textfield?
You cannot!
What you would need to be able to to is create a new class which inherits from both the TextFieldEffects and the ShowPassword. But Swift (same as Objective-C) does not support multiple inheritance (see this answer).
Your only option is to create a custom subclass from one of the classes and create the effect of the second one on your own in your subclass! Meaning that you have to write code to implement the functionality of one of the two desired effects.
Alternatively you can try to create an extension for one of the two library classes adding the logic from the second one. (basically the same thing)
It is highly unlikely that both subclasses would work together without any problems. As soon as both class override the same methods you are in a trouble since you have to decide which one really overrides it, etc.
Related
I'd like to launch multiple HTMLViewer controls. Each should be manage its own cookie storage. If HTMLViewer_1 is already logged in on a site, e.g. HTMLViewer_2 should be able to log in using another role.
Q: How to I isolate HTMLViewer instances against each other?
If I understand your question correctly, I think you should sub-class the HTMLViewer so that the subclassed control can be customized to handle cookie storage (a Property of type Dictionary?) and other custom Methods for any required handling.
Subclassing makes any customized logic or data you add to the HTMLViewer self-contained, when the subclassed control is then added to your UI. A subclassed custom control can be reused multiple times, where each occurrence is a separate instance (with its own internal data).
If you design your new subclassed capabilities well enough, you can hide (Private scope) or encapsulate complexity (new Public Methods) to help make each future use of your subclassed control much easier.
If you're not familiar with subclassing in Xojo, maybe this link can help UserGuide:Subclassing Examples. Also checkout Xojo's YouTube series, there is an example of subclassing a Canvas. Canvas is of course a different control than HTMLViewer, but the actions required in the IDE are basically the same.
I'm currently trying to implement VIPER-architecture in my project, and there is some questions I encountered with.
I have two modules in my app, that have some similar functionality (they both have imagePicker and ability to upload media to server, that implemented absolutely the same for both screens).
My question is how could I reuse this similar functionality in both modules? Trouble is that my imagePicker has many methods declared in Interactor that handle different events while selecting and uploading image (such as didUploadMediaFile(), didFailToUploadMediaFile(), uploadMediaFile() and so on).
Should I create third module with this functionality and then somehow subclass my other modules from it? Or maybe there is a better way of doing it?
The only similar components/methods I'd use are Data Managers, which can be shared between as many Interactors are you want, and yet being 100% compliant with VIPER architecture.
So, a DataManager called, for example, MediaApiDataManager() would be responsible for the implementation of the core code to UploadMediaFile() etc
I suggest you read this post for more great tips on VIPER: https://www.ckl.io/blog/best-practices-viper-architecture/
I think you need create abstract class and implement inside imagePicker logic. Declare interface (protocol) for it class with didUploadMediaFile(), didFailToUploadMediaFile(), uploadMediaFile() methods, implement this methods in class and inject to your VIPER modules
For the two modules try to abstract the similarities and try to build a Class of it. If both classes differs on the data type use Generics, also you can use Protocols, so declare the common methods of the two modules in one protocol and implement each one of them as an extension.
Maybe this tutorial helps. https://medium.com/#richiemon/protocol-extension-dispatching-6d5229f1338e
If I create a subclass of one of Apple's classes, ie: UIViewController, it comes with some methods already defined in the implementation file, ie: -viewDidLoad.
Is there a way to do this with my own classes?
I have been searching for the answer but haven't come up with anything.
Edit: To clarify my Question
I know how to subclass & use protocols etc.
What I want to do is have important methods that should be overridden by a subclass written into the implementation file automatically.
Better example:
If you subclass UITableViewController you will need to implement
-numberOfSections...
-numberOfRows...
-cellForRowAtIndex...
But you don't have to write them yourself, Apple automatically adds them into the file.
So is there something in obj-c that allows me to do that with my classes or is that something Apple has baked into xcode that can only be done by them?
These are basically boiler plate code which is written when the IDE is being designed itself.
Right now I want to split my ViewController, containing public methods, into several files for easier management and navigation. I know that categories can do this, but it's largely used by importing the categories each and everytime you want to use them. The ViewController I'm working on is meant to be subclassed A LOT of times, so that's not really an option.
What I want to achieve is splitting those public methods into categories and combine all those categories into one file, importing them in the header file to ensure that subclasses do not need to import them again and again.
Is there a way to do this? I searched around, but all that I've found is:
Declare the categories in one same header, declare them in multiple implementation file
This is not what I'm looking for, because I heavily document my code inline to take advantage of XCode 5's ability to display inline documents. Navigating the class without using Ctrl+6 is already a nightmare labyrinth due to all the documentation. It will alleviate the problem with implementation file, but not what I'm looking for.
Declare the categories in split headers
All that I've found regarding this are for private uses in that class only (import the categories in the implementation file). I need to split the public methods as well and have them available for subclasses to see.
I thought about creating a class that imports all the categories, essentially hiding the actual class, but that locks me out from protected variables (and I need those).
Is there a... solution to this, or is this really that impossible with the current Objective C?
EDIT:
I've heard that DocSets is the way Apple go to allow them to display documentation without documenting the code inline. If using DocSet allows me to clean up my header code (that is, move the documentation elsewhere) and still have the documentation available in Quick Help, I'd like to learn that
In these circumstances, I would import the necessary categories on the .h of the parent class, this way the subclasses get the categories as well.
Declare your categories in separate header files. Write another header file whose sole purpose is to #include each of the category headers that has public API. Use that single header file when writing subclasses. Write yet another header file that includes the single public file and any additional private category headers, for your internal use.
This is similar to what frameworks do with their classes. Foundation's classes are declared in separate files NSObject.h, NSArray.h, etc. Then Foundation/Foundation.h includes each of the headers for public classes.
I decided to just split the implementation file. Restructuring the class for multiple headers took longer and is harder than I expected. I think the scenario that I posted cannot be solved in the way that I wanted it to be.
I want to have a mail composer view in my app but with a few extra fields and stuff. Since the original view controller Apple provides, MFMailComposeViewController doesn't allow any way to customize it.
So after a little bit of researching I came across the Three20 framework for iOS which provides a view controller called TTMessageController suits my needs. But I did some some checking on this framework and the feedback I've been reading doesn't sound too good. I even tried downloading, following the instructions to add it in a project but that ended up throwing errors also.
My question is, are there any other alternatives to the Three20's TTMessageController? I want to have a view controller where I can add some more input fields to customize it.
Thank you.
Three20 is completely outdated and not suitable for use in a modern Xcode project (using ARC and all the new Objective C features from the last 2 years). Three20 has a very large dependency chain, and you will find yourself stuck trying to make sense of its class heirarchy just to accomplish simple things.
Also, as you correctly pointed out, MFMailComposeViewController cannot be customized in any way other than what is documented by Apple.
The only way to achieve what you want is to start from scratch with an empty UIViewController, and add the text fields you need - either programmatically, or using XIBs or using Storyboards.
I realize this answer doesn't provide you any new information but at least this confirms your feeling that using Three20 for this is a bad idea.