How to customize methods in Collapseclick Library? - ios

I am using Collapseclick library for Acccordian functionality. I am facing issue if trying to call -(UIView *)viewForCollapseClickContentViewAtIndex:(int)index; method and replacing switch case with for loop. I am new to objectiveC. Please help me out!

Honestly it is hard to recommend you a solution without knowing how the library code is set up, but you can try subclassing whatever class implements that method. If that method is on a certain class, make another class that is a subclass of that class and override that method. Expose whatever variables you need to, if they are not already exposed in that library.
See this documentation for more instruction on subclassing:
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html

Related

Is it safe to extend an Objective-C class in Swift with non-prefixed methods?

In Objective-C, one should always prefix category methods, e.g. if extending UIView with the method descendants, you'd add zzz_ and make it zzz_descendants to avoid naming conflicts. Is that necessary for a function in extension UIView { ... } in Swift?
It's not necessary in order to compile. However, it's a good idea to prefix extension methods to avoid possible conflicts later on, in case Apple should introduce a method by the same name. An even more important reason, in my opinion, is to make clear that the extension method is custom code and not part of the standard API.

Subclass an existing Swift Singleton

I am adding functionality to an AWS class that creates a singleton (AWSIdentityManager) and the code for that class is in flux (AWS are improving it). I would like to make my added functionality more distinct from the AWS code so that I don't have to keep changing it when they upgrade.
Can I achieve this by subclassing or extension?
My goal is not to create another copy of the existing singleton, I just want to add methods (and hopefully properties) to it, without making too many changes in the released code.
I should note the following: The original class is written in Obj-C. I would like to have properties if possible.
To extend
extension AWSclass {
func functionA () { ...}
}
usage
AWSclass.shared.functionA()

Swift: UIViewController common function Inheritance

I came from Android background and I'm new to Swift.
I want to know how to use common functions in ViewControllers with DRY principles.
I need all of my ViewControllers to call following functions from one place:
isNetworkAvailable() //check app has internet return boolean
getLoggedinUser() //return logged in user object which I set before
showAlert(message:String) //display a popup
startLoader() // display a loader
stopLoader() // stop loader
As you can see these methods are global and I need to reuse them many times. So I don't want to copy paste the same code over and over again.
In Android I simply make one BaseActivity and put all those methods in it. Later I will extend the BaseActivity into SubActivities and inherit those common methods.
I'm not sure how to do this in "IOS Swift" as all the ViewControllers are attached to StoryBoard.
Can you please tell me what is the best way to achieve this? How does professional Swift developers handle situations like this?
(Please note - I don't want to delete story board and manually create UI elements.)
Thanks in Advance!
Create a CommonFunctions named public class (just a suggestion you can name it any class name which you want) extend it from NSObject and import UIKit Module in it because I think you also want to perform UI Operations in it like startLoader() & stopLoader() then you can write static global methods which you are mentioned in your question.
You can call then using CommonFunctions.methodName().
Or if you don't want to make static functions then create object of CommonFunctions class wherever you want to access those global methods and call the method which you want.

I only have header file from framework in iOS, but need to change property

Here is the things.
I use a framework which contains only header files.
The framework use SOMEWebView which is a subclass of UIWebView.
I need to set this SOMEWebViews property "allowsInlineMediaPlayback" to "YES".
That webView is used by SOMEViewController's UIWebViewDelegate.
How can I make this?
Thanks in advance.
Create a category on SOMEWebView that has the following method declaration:
+ (BOOL)allowsInlineMediaPlayback
{
return YES;
}
EDIT:
N.B. Only do this when you control the code you're overriding. Doing this without knowing what you're doing can cause undesirable behaviour (especially when overriding Apple framework classes using this method). Since you're not in control of the code, I'd suggest you also check out "method swizzling" or see if you can simply subclass the SOMEWebView in question.

How should we document the delegate methods in iOS using Doxygen?

Using Doxygen i have documented the methods declared by me and could generate documentation.
but i am looking for documenting the view life cycle methods and even delegate methods.
Can any one help me in achieving my requirement. All i am looking for is the equivalent documentation in doxygen as { #inherited } in javaDoc
Take a look at this It will give you an idea for what syntax to use for objective-c.
Edit: For docs on the View lifecycle, you would need to decide if you are doing anything outside of the ordinary that justifies needing comments(are you doing more than just updating data on viewwillappear).If you are can the code in those sections be broken out into another method (and then commented on the same as a normal method which would be my suggestion).
Hope this helps.

Resources