Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
dboris committed May 7, 2024
1 parent ee0a3c3 commit b71e871
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,24 @@ module AppDelegate = struct
view |> UIView.setFrame screen_bounds;
view |> UIView.setBackgroundColor (UIColor._class_ |> UIColor.C.systemBackgroundColor);
label |> UILabel.setText (new_string "Hello from OCaml");
label |> UILabel.setText (new_string "Hello from OCaml!");
label |> UILabel.setTextColor (UIColor._class_ |> UIColor.C.systemBlackColor);
label |> UILabel.setTextAlignment Uikit_._UITextAlignmentCenter;
label |> UIView.setFrame screen_bounds;
view |> UIView.addSubview label;
win |> UIWindow.setRootViewController vc;
win |> UIWindow.makeKeyAndVisible;
true
let methods =
[ Define._method_ show_hello
~cmd: (selector "application:didFinishLaunchingWithOptions:")
~args: Objc_t.[id; id]
~return: Objc_t.bool
]
let _class_ = Define._class_ "AppDelegate" ~superclass: "UIResponder" ~methods
let _class_ = Define._class_ "AppDelegate"
~superclass: UIResponder._class_
~methods:
[ Define._method_ show_hello
~cmd: (selector "application:didFinishLaunchingWithOptions:")
~args: Objc_t.[id; id]
~return: Objc_t.bool
]
end
let main () =
Expand Down
4 changes: 2 additions & 2 deletions camlkit/camlkit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module CamlProxy = struct
]

let _class_ =
Def._class_ D.class_name ~superclass: "NSProxy"
Def._class_ D.class_name ~superclass: NSProxy._class_
~methods ~class_methods ~ivars: D.ivars
end
end
Expand Down Expand Up @@ -200,6 +200,6 @@ module CamlObjectProxy = struct
[ ivar_spec ~name: ivar_name ~typ: id ~enc: Objc_t.(Encode.value id) ]
in
_class_ D.class_name
~superclass: "NSProxy" ~ivars ~methods ~class_methods
~superclass: NSProxy._class_ ~ivars ~methods ~class_methods
end
end
8 changes: 4 additions & 4 deletions demo/dune
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(executable
(name main)
; (enabled_if (or
; (= %{context_name} device.ios)
; (= %{context_name} simulator.ios)
; (= %{context_name} catalyst.ios)))
(enabled_if (or
(= %{context_name} device.ios)
(= %{context_name} simulator.ios)
(= %{context_name} catalyst.ios)))
(flags :standard -ccopt "-framework UIKit")
(libraries camlkit-base.foundation camlkit-gui.uikit))

Expand Down
16 changes: 8 additions & 8 deletions demo/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ module AppDelegate = struct
win |> UIWindow.makeKeyAndVisible;
true

let methods =
[ Define._method_ show_hello
~cmd: (selector "application:didFinishLaunchingWithOptions:")
~args: Objc_t.[id; id]
~return: Objc_t.bool
]

let _class_ = Define._class_ "AppDelegate" ~superclass: "UIResponder" ~methods
let _class_ = Define._class_ "AppDelegate"
~superclass: UIResponder._class_
~methods:
[ Define._method_ show_hello
~cmd: (selector "application:didFinishLaunchingWithOptions:")
~args: Objc_t.[id; id]
~return: Objc_t.bool
]
end

let main () =
Expand Down
5 changes: 4 additions & 1 deletion runtime/dune
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
(rule
(enabled_if (and
(= %{system} macosx)
(= %{context_name} default)))
(or
(= %{context_name} default)
(= %{context_name} device)
(= %{context_name} simulator))))
(targets flags.txt platform.ml)
(deps flags.macos platform.macos)
(action (progn
Expand Down
4 changes: 2 additions & 2 deletions runtime/runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,15 @@ struct
let ivar_spec ~name ~typ ~enc = IvarSpec {name; typ; enc}

let _class_
?(superclass = "NSObject")
?(superclass = Objc.get_class "NSObject")
?(protocols = [])
?(ivars = [])
?(methods = [])
?(class_methods = [])
name
=
let self =
Objc.allocate_class ~superclass: (Objc.get_class superclass) name in
Objc.allocate_class ~superclass name in
assert (not (is_null self));

methods |> List.iter (fun (MethodSpec {cmd; typ; imp; enc}) ->
Expand Down

0 comments on commit b71e871

Please sign in to comment.