How to get names of classes inside a jar file?

objective c 클래스를 swift에서 사용하는 경우를 설명

나의 점수는 9/10

참고 ) https://stackoverflow.com/a/24034488/3151712

Posting the answer if it helps some one facing the same issue.

I found that a pretty straight forward solution for How to do this is given in the iOS Developer Library. Please refer to the following link:

https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_75

Apple Doc says:

To import a set of Objective-C files in the same app target as your Swift code, you rely on an Objective-C bridging header to expose those files to Swift. Xcode offers to create this header file when you add a Swift file to an existing Objective-C app, or an Objective-C file to an existing Swift app.

So I created MyApp-Bridging-Header.h file and just added the following line:

#import "MyModel.h"

Now it lets me use the model in my ViewController.swift as follows:

var myModel = MyModel()
myModel.name = "My name"
myModel.dobString = "11 March,2013"
println ("my model values: Name: myModel.name and dob: myModel.dobString")

FYI to anyone who is trying to figure this out. If you have to create the bridging file from scratch, you also have to specify a path to it in Build Settings > Swift Compiler > Objective-C Bridging Header.

cocoapods를 이용한 3rd party library 설치하는 방법

https://cocoapods.org/   cocoapods official website 에 들어가서 cocoapod를 설치하는 터미널 명령어를 복사한 다음 터미널에서 실행

1. xcode프로젝트 화일이 있는 곳으로 터미널 커서를 옮긴다.


2. 그 위치에서 pod init을 통해 pod file을 만든다.

image

3. pod file안에 import할 3rd party library내용을 입력한다.

image
image


4. pod update를 실행하면 library가 설치된다.

image


5. 설치가 끝나면 xcworkspace화일이 생성되고 이를 더블클릭해서 xcode를 연다.

image

아래와 같이 pods폴더가 생성된것을 확인한다.

image


tip)

 이제 부터는 코드상에서 3rd library를 바로 사용가능하다.

만약 안되는 경우는 rebuild를 하고 수행한다.

image


차후 pod화일 수정은 아래에서 수행한다. 

image
image

Visibility from other objects Objects of the same type will have access to each others private and protected members even though they are not the same instances. This is because the implementation specific details are already known when inside those objects.

http://www.phpk.org/archives/301

에서 참조

같은 클래스 안에 속한 정적 함수를 호출 할 때에는 $this 변수를 사용하지 않고 self 키워드를 사용합니다. 이  self 키워드의 특징은 self 를 실행하는 자기 클래스가 아니라 호출하려는 메소드가 정의된 클래스를 의미합니다.

 1: <?php 
 2: class ParentClass { 
 3: public static function who() { 
 4: echo 'I am Parent Class.'; 
 5: } 
 6: 
 7: public static function whoAreYou() { 
 8: self::who(); 
 9: } 
 10: } 
 11: 
 12: class ChildClass extends ParentClass { 
 13: public static function who() { 
 14: echo ' I am Child Class.'; 
 15: } 
 16: } 
 17: 
 18: ChildClass::whoAreYou(); 
 19: 
 20: ?>

위 코드와 같이 ChildClass 가 ParentClass 를 상속 받았습니다. ChildClass 에 있는 whoAreYour() 함수를 호출하여 who() 함수를 실행했을 때 어떤 문자열이 출력될까요.

결과는 I am Parent Class. 입니다.

정적 함수의 상속 관계를 그림으로 보면 아래와 같습니다.

2009-07-15_135134

Last Static Bindings

PHP 5.3.0 에서 추가된 Late Static Bindings는 static 키워드를 추가하여 정의된 부모 클래스가 아니라 상속을 받은 자기 자신을 지징할 수 있도록 했습니다. 코드를 보면 아래와 같습니다.

 1: <?php 
 2: class ParentClass { 
 3: public static function who() { 
 4: echo 'I am Parent Class.'; 
 5: } 
 6: 
 7: public static function whoAreYou() { 
 8: static::who(); 
 9: } 
 10: } 
 11: 
 12: class ChildClass extends ParentClass { 
 13: public static function who() { 
 14: echo ' I am Child Class.'; 
 15: } 
 16: } 
 17: 
 18: ChildClass::whoAreYou(); 
 19: 
 20: ?>

바뀐 부분을 눈치 채셨나요? ParentClass 의 whoAreYou() 함수 안에서 self::who() 코드가  static::who() 로 바뀌었습니다. 이렇게 static 키워드를 사용하면 상속 받은 자식 클래스에서 자신의 함수를 사용할 수 있습니다. 이 static 키워드를 사용하면 아래 코드처럼 작성할 수도 있습니다.

아래 코드에서는 ParentClass 에 who() 함수가 없습니다. 그럼에도 불구하고 ParentClass 에서 who() 를 호출하고 있습니다. 이런 경우 ChildClass 의 who() 가 호출 될 것이므로 ParentClass 에 who() 함수가 정의되어 있지 않아도 됩니다.

 1: <?php 
 2: class ParentClass { 
 3: 
 4: public static function whoAreYou() { 
 5: static::who(); 
 6: } 
 7: } 
 8: 
 9: class ChildClass extends ParentClass { 
 10: public static function who() { 
 11: echo ' I am Child Class.'; 
 12: } 
 13: } 
 14: 
 15: ChildClass::whoAreYou(); 
 16: 
 17: ?>

http://stackoverflow.com/questions/1913098/what-is-the-difference-between-an-interface-and-abstract-class

에서 참조

Difference between interface and abstract class

Interfaces
An interface is a contract: the guy writing the interface say “hey, I accept things looking that way”, and the guy using the interface says “OK, the class I write looks that way”.

An interface is an empty shell, there are only the signatures (name / params / return type) of the methods. The methods do not contain anything. The interface can’t do anything. It’s just a pattern.

E.G (pseudo code):

// I say all motor vehicles should look like that :
interface MotorVehicle
{
void run();

int getFuel();
}

// my team mate complies and write vehicle looking that way
class Car implements MotorVehicle
{

int fuel;

void run()
{
print(“Wrroooooooom”);
}

int getFuel()
{
return this.fuel;
}
}
Implementing an interface consume very little CPU, because it’s not a class, just a bunch of names, and therefor there is no expensive lookup to do. It’s great when it matters such as in embedded devices.

Abstract classes
Abstract classes, unlike interfaces, are classes. There are more expensive to use because there is a lookup to do when you inherit from them.

Abstract classes look a lot like interfaces, but they have something more : you can define a behavior for them. It’s more about a guy saying “these classes should look like that, and they got that in common, so fill in the blanks!”.

e.g:

// I say all motor vehicles should look like that :
abstract class MotorVehicle
{

int fuel;

// they ALL have fuel, so why let others implement that ?
// let’s make it for everybody
int getFuel()
{
return this.fuel;
}

// that can be very different, force them to provide their
// implementation
abstract void run();

}

// my team mate complies and write vehicle looking that way
class Car extends MotorVehicle
{
void run()
{
print(“Wrroooooooom”);
}
}
Implementation
While abstract classes and interfaces are supposed to be different concepts, the implementations make that statement sometimes untrue. Sometimes, they are not even what you think they are.

In Java, this rule is strongly enforced, while in PHP, interfaces are abstract classes with no method declared.

In Python, abstract classes are more a programming trick you can get from the ABC module and is actually using metaclasses, and therefore classes. And interfaces are more related to duck typing in this language and it’s a mix between conventions and special methods that call descriptors (the __method__ methods).

As usual with programming, there is theory, practice, and practice in another language 🙂