2020년 7월 27일 월요일

Using Swift framework in an Objective-c project

reference
https://marcinczenko.github.io/post/using-swift-frameworks-from-objective-c-target/


===============================================
=============== Swift Framework ===============
===============================================
Make a ExampleSwiftFramework framework. not Static Library
Add ExampleSwiftFramework.swift and put the code below

@objc
public class ExampleSwiftFrameworkClass : NSObject {

    let message: String

    @objc(init:)
    public init(withHelloMessage message: String) {
        self.message = message
    }

    @objc(sayHello)
    public func sayHello() -> String {
        return self.message
    }
}

TARGETS->Build Settings
Mach-O : 'Dynamic Library'

Build Options->Always Embeded Swift Standard Libraries : No
Packaging->Defines Module : Yes
Apple Clang-Language-Modules->Enable Modules(C and Objective-C) : Yes

next to the upper left 'stop' icon. click framework and edit scheme->Run->Build Configuration=> Release

Click Product->Build
and you can see the built framework on the project navigato.
Right click at the file->Show in Finder

===============================================
============= Objective-C project =============
===============================================
Make an objective-C project

TARGETS->General
1. add the swift framework into the 'Frameworks, Libraries, and Embedded Content'
2. and then you can see 'Framework' folder in the project navigator.
3. remove the framework from the 'Frameworks, Libraries, and Embedded Content'
4. drag the framework.framework folder into the 'Framework' in the project navigator

TARGETS -> Build Settings(All, Combined taps)
Build Option -> Always Embed Swift Standard Libraries : No

TARGETS -> Build Phases
Click '+' and add New Copy Files Phase category
add the swift framework what you need and keep the default option(Code Sign On Copy : checked, Copy only when installing : unchecked)

put the code below in -(void)viewDidLoad

ExampleSwiftFrameworkClass *exam = [[ExampleSwiftFrameworkClass alloc] init:@"Test"];
NSLog(@"%@", [exam sayHello]);

2020년 7월 19일 일요일

Room migrations in Kotlin

To test you need two class 

//===============================================================
// AppDatabase class
Database(entities = [Song::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {
        companion object {
        @Volatile private var INSTANCE: AppDatabase? = null
        fun getInstance(context: Context): AppDatabase =
            INSTANCE ?: synchronized(this) {                
         INSTANCE ?: buildDatabase(context).also {INSTANCE = it }}
        private fun buildDatabase(context: Context) =              
        Room.databaseBuilder(context.applicationContext,                  
        AppDatabase::class.java, "test.db").build()
        fun destroyInstance() {
            INSTANCE = null        
        }
    }
}

//===============================================================
// Entity class
// when the version was 1
@Entitydata class Song(
    @PrimaryKey val id: Long,    val title: String
)
//===============================================================


When you run an app with the database version 1
after then you modified the Song class added 'tag' entity.
@Entitydata class Song(
    @PrimaryKey    val id: Long,    
    val title: String,    
    val tag: String // Added in version 2.
)
you should change the version number of AppDatabase class like below from 1 to 2
Database(entities = [Song::class], version = 2, exportSchema = false)

you also have to edit database builder like this

private fun buildDatabase(context: Context) =
     Room.databaseBuilder(context.applicationContext, 
          AppDatabase::class.java, "terry.db")
          .addMigrations(MIGRATION_1_2).build()

and add migration code or edit it in the Song class
// Migration from 1 to 2, Room 2.1.0val MIGRATION_1_2 = object : Migration(1, 2) {
    override fun migrate(database: SupportSQLiteDatabase) {
        database.execSQL(
            "ALTER TABLE Song ADD COLUMN tag TEXT NOT NULL DEFAULT ''")
    }
}

That's all! :)


2020년 6월 12일 금요일

우분투(18.04) 설치 후 윈도우(Win10 pro) 설치(멀티부팅)

https://goodtogreate.tistory.com/entry/%EB%A9%80%ED%8B%B0%EB%B6%80%ED%8C%85-%EC%9A%B0%EB%B6%84%ED%88%AC-%EC%84%A4%EC%B9%98-%ED%9B%84-%EC%9C%88%EB%8F%84%EC%9A%B0-Install-Windows10-alongside-Ubuntu

우분투 카톡 설치

와인설치는 아래 링크 먼저 확인해서 설치.
와인 버전 설치할 때 우분투 버전 18, 19 구분하는 옵션 부분 잘 확인해서 설치

카톡설치
https://lucidmaj7.tistory.com/159

와인설치
http://ubuntuhandbook.org/index.php/2020/01/install-wine-5-0-stable-ubuntu-18-04-19-10/

우분투 18.04에 윈도우 10 멀티부팅

윈도우 설치 후 재부팅하면 오랫동안 진행이 안되는 것 같은데 완료됨.
네트웍이 무선이 아니라 유선으로 연결을 해야진행되는 걸 수도 있음.
무선으로 연결해서 한참 기다려도 윈도우화면 안나와서 몇번 설치 실패.
유선 연결 후 20 ~ 30분 정도 기다린 후 정상 설치 됨. 무선에서 더기다려서 될수도 있음.

https://goodtogreate.tistory.com/entry/%EB%A9%80%ED%8B%B0%EB%B6%80%ED%8C%85-%EC%9A%B0%EB%B6%84%ED%88%AC-%EC%84%A4%EC%B9%98-%ED%9B%84-%EC%9C%88%EB%8F%84%EC%9A%B0-Install-Windows10-alongside-Ubuntu

Ubuntu 18.04 Wine 설치

http://ubuntuhandbook.org/index.php/2020/01/install-wine-5-0-stable-ubuntu-18-04-19-10/