Author: Smin Rana

  • SwiftUI for Flutter developer – Video 1

    As a flutter developer, there are not many things you can do on Xcode since Flutter itself builds everything for you but why not learn some app development with Swift and Xcode.

    Swift is a deep and large language and I find it complex, when I learned Objective-C back in 2010 with Xcode 3.x that was very hard to start but later it became easy for me.

    Today there is no reason to start learning Objective-C over Swift unless you have a specific interest.

    For Flutter developers, if flutter is your first mobile framework and dart is the first language you may find Swift is complex and hard to start but the idea behind all the languages is the same you just have to learn the syntax. Of course, some languages have specific features for some reasons.

    I have a series of videos for Flutter developers who want to learn Swift App Development with Xcode. For running Xcode you just need a Mac computer. Running Xcode on any Mac will work, most of the time you don’t need a very powerful Mac.

    I’m very new to making videos and teaching programming to others, if you find anything wrong, just let me know in the comments. Also if you can subscribe to my channel and like the video, I’m gonna appreciate that.

    So this is the first video, there going to be a few more videos. We are going to make an app with a login page and list page. We also going to use some APIs which also we are going to make ourselves in PHP.

    https://www.youtube.com/watch?v=f4kXQBsZBoI
    Spread the love
  • Call swift native code from Flutter

    In this tutorial, we are going to call a simple swift method of AppDelegate.swift file from flutter.

    Let’s create a brand new flutter app by running the following command on your terminal

    flutter create ios_native

    Delete everything inside the method _incrementCounter() on your main.dart file and make it an async method.

     Future<void> _incrementCounter() async {
        const MethodChannel _channel =
            const MethodChannel("FlutterFramework/swift_native");
        final result = await _channel.invokeMethod('getSum');
        print("result from iOS native + Swift ${result}");
      }

    Now open your Runner.xcworkspace on Xcode and open AppDelegate.swift

    private func getSum() -> Int {
        return 2 + 2
     }

    Add the following code in the method didFinishLaunchingWithOptions and close the Xcode.

     let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
          let channel = FlutterMethodChannel(name: "FlutterFramework/swift_native",
                                             binaryMessenger: controller.binaryMessenger)
          channel.setMethodCallHandler({
              [weak self]  (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
              // This method is invoked on the UI thread.
              // Handle battery messages.
              guard call.method == "getSum" else {
                  result(FlutterMethodNotImplemented)
                  return
              }
    
              result(self?.getSum())
          })

    Now run the flutter app on the VSCode or Android Studio, if you click the floating button you will swift method returns 2 +2 = 4

    Call native Android code from Flutter

    Spread the love