Person<Person>, what is <Person>? - ios

I cloned an iOS project from git repository. The project is written in Objective-C.
I saw this code in a header file:
#interface Employee: Person<Person> {
...
}
What does Person <Person> mean? I know it indicates Employee is a subclass of Person but what is the special meaning of <Person> ?

Employee is a subclass of a class called Person and also conforms to a protocol called Person.
#interface MySubclass : MySuperclass <MyProtocol> { ... }

Related

swift call oc class getter method in oc project

oc project;
I has class like this
#interface MyObject : NSObject
#property(noatomic,getter=getNode)id node;
#end
and in swift file
var node = MyObject().getNode
and getNode method not found ?
anyone helps

How to transfer a Class to another Class in Objective-C?

ForExample ,I Have a Class named PlayListModel, which have a properties:id . and I have other Classes like PlayModel_A or PlayModel_B ,which have many properties。
Now what I want is there have a method like:
- (PlayListModel*)transferAnClass:(id)anClass ToPlayListModel;
I want transfer other model to the uniform PlayListModel , than pass the PlayListModel to the player.
My problem is , the other model's source name is different. some is 'idField' and some is 'idsource' or something other . so the need to transfer them to the Playlist's property name :'id'(for example).
i tried to use run time , but i can't get the definitely name of class, they could be any modelClasses.
I can use [class Class] to know which class it is . but then I can't use Class.property . I don't know how to explain .
It sounds like what you want to do is subclass People..
#interface Student : People
//properties & method names here
#end
#implementation Student
//code here
#end
You can create a model of People separately and use object of that model in Student or Police
class People {
private var _age : Int = 0
private var _name : String = ""
}
and Student class as
class Student {
private var _student_id : Int = 0
private var _student_rollno : String = ""
let _people : People
}
if you need to send data you can directly pass object of Student or Police class.
You can also opt for inheritance.Inherit your People class in Student or Police class. You can access and modify properties of People class in Student or Police class easily.

How to handle static frameworks dependencies

I am trying to build Objective-C static frameworks but ran into hierarchy/organization problems.
For the question, assume I have 3 classes, classA, classB, and classC. classB and classC are children classes of classA. classB and classC each needs special resource files.
#import "classB.h"
#import "classC.h"
#implement classA
+ (classA)factoryMethodCreateType:(NSString *)type {
classA a;
if ([type isEqualToString:#"classB"]) {
a = [[classB alloc] init];
} else if ([type isEqualToString:#"classC"]) {
a = [classC alloc] init];
}
return a;
}
#end
I'd like to statically package the frameworks, classB.framework and classC.framework, such that when a user wants to use classB, they don't need to include classC and its resource files. Additionally, the user can use classA as the entry point to use either of the frameworks.
I assume if I just create classB.framework (includes classA and classB) and classC.framework (includes classA and classC), when the user wants to use both types and include both frameworks, the user will face duplicate symbols?
What is the best way to handle this situation? Is the following approach the best way to do it?
Change classA's implementation to dynamic creation of classB or classC and not include their header files.
Build 3 frameworks instead of 2: classA.framework, classB.framework, classC.framework. When the user wants to use classB, the the user should include both classA.framework and classB.framework.
#implement classA
+ (classA)factoryMethodCreateType:(NSString *)type {
classA a;
id obj = [NSClassFromString(type) alloc];
a = objc_msgSend(obj, #selector(init));
return a;
}
#end

NS_ENUM error when declared before class instance variables

Example .h file:
#interface MyClass : NSObject
typedef NS_ENUM(int, myType) {
Something,
SomethingElse,
SomethingElseElse,
YetAnotherSomethingElse
};
{ //Error On This Line: Expected Identifier or '('
int aInstanceVariable;
}
//Some Methods go here
#end
Why am I getting that error (see the comment in the code above)? It works fine when below the class instance variable declaration, but I would like to use it as the type for one of my instance variables.
Thanks to #CarlVeazey, I discovered that the answer was simple: Move the typedef declaration to above #interface. The reason for this is that types cannot be owned by a class or an instance of a class, and therefore cannot be in the interface for a class.

Getting error use of undeclared identifier "value" when assigning parameter to variable

When I assign value to age, I get this error:
#interface Person : NSObject
{
int age;
}
-(void)setAge;
#end
I tried to use self.age, yet it did not work
Here is my .m file:
#implementation Person
-(void)setAge(int)value
{
age = value;
}
#end
I tried several differnet things. ..I get this error when I type this: age = value; do you know why this is?
You should add:
-(void)setAge:(int)value;
In the header file because the current method specification you have there doesn't have a parameter.
Your method in the implementation should also have the same spec as it's missing a colon currently.
You have actually declared one method (-setAge) and implemented another (-setAge:, note the colon). You should really declare age as a property and avoid explicit ivars as much as possible. Also, I hope you have properly formatted the class in your real code.
#interface Person : NSObject
#property (nonatomic) int age;
#end
#implementation Person
-(void)setAge:(int)value
{
_age = value;
}
#end
Note that it is no longer necessary to explicitly #synthesize properties, and they automatically synthesize with an underscored ivar.

Resources