rm-extensions 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -1
- data/lib/motion/rm-extensions.rb +24 -13
- data/lib/rm-extensions/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -6,6 +6,9 @@ Extensions and helpers for dealing with various areas of rubymotion:
|
|
6
6
|
- block/scope/local variable issues
|
7
7
|
- GCD blocks
|
8
8
|
- retaining objects through async procedures
|
9
|
+
- weak attr_accessors
|
10
|
+
|
11
|
+
Currently depends on bubblewrap and BlocksKit.
|
9
12
|
|
10
13
|
## Installation
|
11
14
|
|
@@ -13,13 +16,17 @@ Add this line to your application's Gemfile:
|
|
13
16
|
|
14
17
|
gem 'rm-extensions'
|
15
18
|
|
19
|
+
Add this line to your application's Rakefile:
|
20
|
+
|
21
|
+
pod 'BlocksKit'
|
22
|
+
|
16
23
|
And then execute:
|
17
24
|
|
18
25
|
$ bundle
|
19
26
|
|
20
27
|
## Usage
|
21
28
|
|
22
|
-
|
29
|
+
Some code is commented. TODO.
|
23
30
|
|
24
31
|
## Contributing
|
25
32
|
|
data/lib/motion/rm-extensions.rb
CHANGED
@@ -5,18 +5,27 @@ module RMExtensions
|
|
5
5
|
|
6
6
|
def rmext_weak_attr_accessor(*attrs)
|
7
7
|
attrs.each do |attr|
|
8
|
+
ptr = Pointer.new(:object)
|
9
|
+
ptr.assign(attr.to_sym)
|
8
10
|
define_method(attr) do
|
9
|
-
|
10
|
-
val.nonretainedObjectValue
|
11
|
-
end
|
11
|
+
associatedValueForKey(ptr)
|
12
12
|
end
|
13
13
|
define_method("#{attr}=") do |val|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
weaklyAssociateValue(val, withKey:ptr)
|
15
|
+
val
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def rmext_copy_attr_accessor(*attrs)
|
21
|
+
attrs.each do |attr|
|
22
|
+
ptr = Pointer.new(:object)
|
23
|
+
ptr.assign(attr.to_sym)
|
24
|
+
define_method(attr) do
|
25
|
+
associatedValueForKey(ptr)
|
26
|
+
end
|
27
|
+
define_method("#{attr}=") do |val|
|
28
|
+
associateCopyOfValue(val, withKey:ptr)
|
20
29
|
val
|
21
30
|
end
|
22
31
|
end
|
@@ -157,8 +166,7 @@ module RMExtensions
|
|
157
166
|
end
|
158
167
|
|
159
168
|
def rmext_on_dealloc(&block)
|
160
|
-
internalObject = ::RMExtensions::OnDeallocInternalObject.create(
|
161
|
-
internalObject.obj = self
|
169
|
+
internalObject = ::RMExtensions::OnDeallocInternalObject.create("#{self.class.name}:#{object_id}", self, block)
|
162
170
|
@rmext_on_dealloc_blocks ||= {}
|
163
171
|
@rmext_on_dealloc_blocks[internalObject] = internalObject
|
164
172
|
nil
|
@@ -316,14 +324,17 @@ module RMExtensions
|
|
316
324
|
end
|
317
325
|
|
318
326
|
class OnDeallocInternalObject
|
319
|
-
attr_accessor :block
|
327
|
+
attr_accessor :description, :block
|
320
328
|
rmext_weak_attr_accessor :obj
|
321
|
-
def self.create(
|
329
|
+
def self.create(description, obj, block)
|
322
330
|
x = new
|
331
|
+
x.description = description
|
332
|
+
x.obj = obj
|
323
333
|
x.block = block
|
324
334
|
x
|
325
335
|
end
|
326
336
|
def dealloc
|
337
|
+
# p "dealloc OnDeallocInternalObject #{description}"
|
327
338
|
if block
|
328
339
|
block.call(obj)
|
329
340
|
self.block = nil
|