kommen / clojure-objc

Clojure for objc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Clojure for objc


Languages

Language:Java 57.7%Language:Clojure 36.1%Language:C 2.8%Language:Objective-C 2.6%Language:HTML 0.7%Language:Shell 0.0%