Skip to content

Instantly share code, notes, and snippets.

@johnny77221
Created October 29, 2020 06:14
Show Gist options
  • Save johnny77221/2aa65f3610c2da7e5754daa8045a43f7 to your computer and use it in GitHub Desktop.
Save johnny77221/2aa65f3610c2da7e5754daa8045a43f7 to your computer and use it in GitHub Desktop.

Revisions

  1. johnny77221 created this gist Oct 29, 2020.
    9 changes: 9 additions & 0 deletions SwiftUser.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    import UIKit

    class SwiftUser: UIViewController {
    override func viewDidLoad() {
    super.viewDidLoad()
    TestLib().myFunc()
    }

    }
    7 changes: 7 additions & 0 deletions TestLib.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    import Foundation

    @objc class TestLib: NSObject {
    @objc fileprivate func _myFunc() {
    print("I am here")
    }
    }
    6 changes: 6 additions & 0 deletions TestLib_Objc.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    #import "test-Swift.h"

    @interface TestLib (Ext)
    -(void)myFunc NS_SWIFT_UNAVAILABLE("objc only");
    @end

    24 changes: 24 additions & 0 deletions TestLib_Objc.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #import "TestLib_Objc.h"

    @implementation TestLib(Ext)
    -(void)myFunc {
    [self performSelector:NSSelectorFromString(@"_myFunc")];
    }

    @end


    @interface TestObjcUser: NSObject
    @end
    @implementation TestObjcUser

    - (instancetype)init
    {
    self = [super init];
    if (self) {
    [[[TestLib alloc] init] myFunc];
    }
    return self;
    }

    @end