Select what methods from super class to Implement/Override in xcode - xcode

Is there a way to select/see what methods you can override/implement from the super class in xcode and have them created?
An example of what I mean is in Visual Studio you can select from a drop down at the top of the class file and if that method is not in your class it will get created.
In Android Studio you can right click on the class name/Generate/Override Methods and it brings up a list of the class methods that you can override.
Does such a thing exist in xcode so that I dont have to keep looking at the online documentation when I need to find something?

I understand what you're asking for well enough to know that this isn't exactly it however I couldn't pass up an opportunity get this very useful technique on "the stack(overflow)"! ;-) Add this method to any (NSObject sub-)class and it will log all unimplemented methods that the runtime is attempting to resolve against your class.
/*******************************************************************************
** Function - resolveInstanceMethod
**
** This is an AWESOME debugging method that allows you to see what methods
** the runtime is attempting to resolve against your class
********************************************************************************/
#ifdef DEBUG
+ (BOOL) resolveInstanceMethod:(SEL)sel {
BOOL result = [super resolveInstanceMethod:sel];
// comment out this next line if you want to
// log methods implemented by the super class
if (!result)
{
NSLog(#"Unimplemented Instance method: \'%s\'", sel_getName(sel));
}
return (result);
} /* resolveInstanceMethod: */
#endif // def DEBUG

Related

Hook in CLLocationManagerDelegate protocol

I have a problem from 3 days :( I want to hook in CLLocationManagerDelegate protocol this method:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
I tried everything but without success. I know how to hook into class or framework but I can't find a solution to hook a Delegate.
Please help me!
Thanks
Hooking requires you to provide objective-C class you would like to hook. This is what Class type is for. One way to get obj-c class is by name via objc_getClass function. But in your case as I understand it correctly you don't have the name. You want to hook every class that conforms to CLLocationManagerDelegate protocol and implements specific method. Here is what you can do.
You can obtain every registered obj-C class and search for those which conform toCLLocationManagerDelegate protocol like this:
static IMP original_didUpdateLocations;
void replaced_didUpdateLocations(id self, SEL _cmd, CLLocationManager* manager, NSArray* locations)
{
NSLog(#"%# did update locations to %#", manager, locations);
original_didUpdateLocations(self, _cmd, manager, locations);
}
...
#import <objc/runtime.h>
int numClasses = objc_getClassList(NULL, 0);
Class* list = (Class*)malloc(sizeof(Class) * numClasses);
objc_getClassList(list, numClasses);
for (int i = 0; i < numClasses; i++)
{
if (class_conformsToProtocol(list[i], #protocol(CLLocationManagerDelegate)) &&
class_getInstanceMethod(list[i], #selector(locationManager:didUpdateLocations:)))
{
MSHookMessageEx(list[i], #selector(locationManager:didUpdateLocations:), (IMP)replaced_didUpdateLocations, (IMP*)&original_didUpdateLocations);
}
}
free(list);
We need to know how many classes there is. objc_getClassList(NULL, 0) returns number of all registered classes.
Allocating memory with malloc(sizeof(Class) * numClasses) and filling it with objects of type Class using objc_getClassList(list, numClasses).
Searching through all these classes for those which conform to CLLocationManagerDelegate protocol and implement locationManager:didUpdateLocations: method. If we found one we are hooking it with our own implementation.
In our own implementation we are printing some debug message and calling original implementation before returning. Of course, you can do whatever you what, this is just an example.
Freeing allocated memory using free(list).

grails 2.2.2 platform-core-plugin No signature of method event in domain model

I try out the platform-core-1.0 rc5 Plugin to services by events. Now I write a service in the grails-plugin "listadmin":
package listadmin
class SECO_ListenService {
#grails.events.Listener(topic='getEntriesOfList', namespace='listadmin')
def getEntriesOfList(String intnalListName) {
println "SECO_ListenService"
def Liste aList = Liste.findByInternal_name(intnalListName)
return aList.eintrage.toList()
}
}
This service should return a list for dropdown in an other grails-plugin called "institutionadmin". I want to use this list of the service for a dropdown of a domain-model. I should mention that I use dynamic scaffolding. Now I try to call this event in the domain-model:
package institutionadmin
import org.springframework.dao.DataIntegrityViolationException
class Einrichtung {
Long einrichtungs_type
Long type_of_conzept
int anzahl_gruppen
int anzahl_kinder_pro_Gruppe
String offnungszeiten
static hasMany = [rooms : Raum]
static constraints = {
def aList = []
def reply = event(for:"listadmin", topic:"getEntriesOfList", data:"einrichtung_type").waitFor()
aList = reply.value.toList()
einrichtungs_type(inList: aList)
}
}
If I try to run this application i get the following error:
Caused by MissingMethodException: No signature of method: institutionadmin.Einrichtung.event() is applicable for argument types: (java.util.LinkedHashMap) values: [[for:listadmin, topic:testEventBus]]
Possible solutions: ident(), every(), every(groovy.lang.Closure), count(), get(java.io.Serializable), print(java.lang.Object)
If call this event in a controller everything is fine and the documentation of this plugin describe that I can call events also in domain-models and services... This error-method tell me, that the class don't know the event method.
Do I have to configure anything else?
Should call the event in another way or where is my mistake?
Has anybody experiences with this module?
The event(...) dynamic methods are not available on class (static) level.
You can pull the grailsEvents spring bean and call its event() method alternatively. You still have to get the bean from the application context statically though.
You could also use a custom validator instead, as you can get the current domain instance as a parameter, which should have the event() method injected.
something like this :
static myList = []
static constraints = {
einrichtungs_type validator: { value, instance ->
if(!myList){
// cache it the first time you save/validate the domain
// I would probably recommend you NOT to do this here though in
// real life scenario
def reply = instance.event('blabla').get()
myList = reply.value.toList()
}
return value in myList
}
}
Anyway, In my case I would probably load the list elsewhere (in the Bootstrap.groovy for instance) and use it / inject it in my domain instead of doing in the constraints closure.
I faced similar kind of problem, I wanted to use the event call inside a service class which is going to call the listener in other service class. When I started my application I got the same error.What I did was, added the plugin(platform-core:1.0.RC5) entries in BuildConfig.groovy like below
plugins {
build(":tomcat:$grailsVersion",
":platform-core:1.0.RC5") {
export = false
}
compile ':platform-core:1.0.RC5'
runtime ':platform-core:1.0.RC5'
}
Then I ran grails > clean and grails > compile on that project and restarted the server.It started working. Might be you can give a try.

Difference between login.event and logout.event in liferay

I hooked up these two events with one class and my question is How can I recognize when the class is called by login.event and when by logout.event.
My class extends Action.
The easiest way that comes to my mind: Implement the two events in different classes. If you desperately want the implementation to be in a single class, delegate to it from the action classes.
I prefer also the solution from Olaf, to take two separate classes. But if you have hard requirements to use olny one class, then you can try to recognise the event type about the called stack trace.
private void printStackTrace() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
System.out.println(stackTraceElement.getClassName() + "." + stackTraceElement.getMethodName());
}
}

Obj-C Private Method Compiler Warnings

Private methods are a useful construct to keep code organised within class boundaries. An example being the organisation of long winded Quartz 2d instructions in a custom UIView subclass. I am able to include such methods in '.m' files with no declaration in '.h'. A working example from a UIView subclass '.m' file reads:
-(void)DoSomethingPrivate { //Not declared in interface
NSLog(#"Does this print a private function?");
}
- (id)initWithFrame:(CGRect)frame //Declared in inherited interface
{
self = [super initWithFrame:frame];
if (self) {
[self DoSomethingPrivate]; //Error: 'Instance method not found'
} //... but it works anyway.
return self;
}
My problem is that the compiler generates the warning "Instance method '-DoSomethingPrivate' not found (return type defaults to 'id')" on the line calling the private function. I'm aware from responses to this question that I can use a 'no name' interface category to 'hide' private method declarations.
However, when I review Apple sample code SimpleStocks, file "SimpleStockView.m", it contains a private function which is neither declared in a no-name category interface, nor does it generate compiler warnings:
//Private Function
- (void)drawRadialGradientInSize:(CGSize)size centeredAt:(CGPoint)center {
...
}
//Is called by this function...
- (UIImage *)patternImageOfSize:(CGSize)size {
...
//The next line doesn't generate any warnings!
[self drawRadialGradientInSize:size centeredAt:center];
...
}
I'd be grateful if anyone can shed any light on how Apple's sample-code private-methods appear to escape compiler checks, so I may avoid having to maintain a 'no-name' category header with all my private methods.
Many thanks.

typedef struct syntax for C++ Windows Forms?

i'm having trouble with syntax regarding c++ Windows Forms..
this is how you obviously do it in a regular cpp project: http://www.cplusplus.com/doc/tutorial/structures/
but its not the same in windows forms :/
any help??
THANKS!
btw, i figured it out!
you must create a new class in the project...
call it, Player.h
in the new class, you must instantiate the class like below
to make it a managed class so it fits well with the managed code
in the forms (notice ref class keyword)
struct markedPos
{
int xPos;
int yPos;
};
ref class Player
{
public:
Player()
{
}
protected:
private:
};
then simply in the forms.h file, you must include the new class like any other class:
#include "Player.h"
and all you have to do is make an instance of the player in your forms and it'll work like magic! What i've learned: Do all your heavy lifting in the managed classes outside of the forms... which work just like your regular c++ classes...
cheers!
** You don't need to use managed code! if your getting problems with it, just remove 'ref' before class name

Resources