galdolber/clojure-objc

Clojure for objc

Java

245

2,739 commits

updated Jul 19, 2015

See the code

README

clojure-objc

A Clojure compiler that targets objc runtimes.

  • Write native apps in Clojure
  • Strong iOS support
  • Future proof: shares 99.99% of the code base with clojure for the jvm
  • Distribute clojure-objc libs using maven
  • Most existing Clojure libs should just work
  • ObjC interop
  • C interop
  • ObjC subclassing
  • REPL!

alt usage guide

Leiningen plugin

https://github.com/galdolber/lein-objcbuild

Dependency

Clojars Project

Memory management

All generated code manage memory automagically, but if you alloc with interop you need to release!

ObjC interop

;; calling objc methods
(defn say-hi [name]
  (-> ($ UIAlertView)
      ($ :alloc)
      ($ :initWithTitle (str "Hello " name)
         :message "Hi! from clojure"
         :delegate nil
         :cancelButtonTitle "Cancelar"
         :otherButtonTitles nil)
      ($ :autorelease)
      ($ :show)))

;; extend objc class
(defnstype UIKitController UIViewController
  ([^:id self :initWith ^:id [view s]]
     (doto ($$ self :init)
       ($ :setView ($ view :retain))
       (objc-set! :scope s)
       (#(post-notification ($ % :view) :init)))))
       
;; c interop
(defc NSLog :void [:id &]) ; & for variadic
(NSLog "%@ %@ %d" "Hello" "World" 13)

;; proxy objc class
(nsproxy
  ([^:bool self :textFieldShouldReturn ^:id field]
    ($ field :resignFirstResponder) 
    true))
  

Presentations

http://www.slideshare.net/GalDolber/clojureobjc-47500127

Discuss

https://groups.google.com/d/forum/clojure-objc-discuss

How to build dist

lein exec build.clj

License

Portions of this project derived from Clojure: Copyright © 2006-2015 Rich Hickey

Original code and Clojure modifications: Copyright © 2014-2015 Gal Dolber

Both are distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Contributors

(top 30 of 99)

richhickey

1,736 commits

galdolber

229 commits

stuarthalloway

226 commits

puredanger

83 commits

galdolber/clojure-objc

Clojure for objc

Java

245

2,739 commits

updated Jul 19, 2015

See the code

README

clojure-objc

A Clojure compiler that targets objc runtimes.

  • Write native apps in Clojure
  • Strong iOS support
  • Future proof: shares 99.99% of the code base with clojure for the jvm
  • Distribute clojure-objc libs using maven
  • Most existing Clojure libs should just work
  • ObjC interop
  • C interop
  • ObjC subclassing
  • REPL!

alt usage guide

Leiningen plugin

https://github.com/galdolber/lein-objcbuild

Dependency

Clojars Project

Memory management

All generated code manage memory automagically, but if you alloc with interop you need to release!

ObjC interop

;; calling objc methods
(defn say-hi [name]
  (-> ($ UIAlertView)
      ($ :alloc)
      ($ :initWithTitle (str "Hello " name)
         :message "Hi! from clojure"
         :delegate nil
         :cancelButtonTitle "Cancelar"
         :otherButtonTitles nil)
      ($ :autorelease)
      ($ :show)))

;; extend objc class
(defnstype UIKitController UIViewController
  ([^:id self :initWith ^:id [view s]]
     (doto ($$ self :init)
       ($ :setView ($ view :retain))
       (objc-set! :scope s)
       (#(post-notification ($ % :view) :init)))))
       
;; c interop
(defc NSLog :void [:id &]) ; & for variadic
(NSLog "%@ %@ %d" "Hello" "World" 13)

;; proxy objc class
(nsproxy
  ([^:bool self :textFieldShouldReturn ^:id field]
    ($ field :resignFirstResponder) 
    true))
  

Presentations

http://www.slideshare.net/GalDolber/clojureobjc-47500127

Discuss

https://groups.google.com/d/forum/clojure-objc-discuss

How to build dist

lein exec build.clj

License

Portions of this project derived from Clojure: Copyright © 2006-2015 Rich Hickey

Original code and Clojure modifications: Copyright © 2014-2015 Gal Dolber

Both are distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Contributors

(top 30 of 99)

richhickey

1,736 commits

galdolber

229 commits

stuarthalloway

226 commits

puredanger

83 commits

Languages

Java

57.7%

Clojure

36.1%

C

2.8%

Objective-C

2.6%