Skip to content

Commit b67afb7

Browse files
committed
Better Objective-C interopability.
1 parent d7ee5e9 commit b67afb7

File tree

3 files changed

+35
-125
lines changed

3 files changed

+35
-125
lines changed

ColorSetKit/ColorSetStream.swift

Lines changed: 32 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ import Cocoa
7373
return
7474
}
7575

76-
self.append( uInt64: UInt64( string.count ) + 1 )
76+
self.append( value: UInt64( string.count ) + 1 )
7777
self.data.append( data )
78-
self.append( uInt8: 0 )
78+
self.append( value: UInt8( 0 ) )
7979
}
8080
}
8181

@@ -101,211 +101,120 @@ import Cocoa
101101

102102
rgb.getRed( &r, green: &g, blue: &b, alpha: &a )
103103

104-
self.append( double: Double( r ) )
105-
self.append( double: Double( g ) )
106-
self.append( double: Double( b ) )
107-
self.append( double: Double( a ) )
104+
self.append( value: Double( r ) )
105+
self.append( value: Double( g ) )
106+
self.append( value: Double( b ) )
107+
self.append( value: Double( a ) )
108108
}
109109
}
110110

111111
/**
112112
* Appends a `UInt8` value to the stream.
113113
*
114-
* - parameter uInt8: The `UInt8` value to append.
114+
* - parameter value: The `UInt8` value to append.
115115
*/
116116
@objc( appendUInt8: )
117-
public func append( uInt8: UInt8 )
117+
public func append( value: UInt8 )
118118
{
119119
self.synchronized
120120
{
121-
var value = uInt8.littleEndian
121+
var v = value.littleEndian
122122

123-
self.data.append( &value, count: 1 )
123+
self.data.append( &v, count: 1 )
124124
}
125125
}
126126

127127
/**
128128
* Appends a `UInt16` value to the stream.
129129
*
130-
* - parameter uInt16: The `UInt16` value to append.
130+
* - parameter value: The `UInt16` value to append.
131131
*/
132132
@objc( appendUInt16: )
133-
public func append( uInt16: UInt16 )
133+
public func append( value: UInt16 )
134134
{
135135
self.synchronized
136136
{
137-
var value = uInt16.littleEndian
137+
var v = value.littleEndian
138138

139-
self.data.append( UnsafeBufferPointer( start: &value, count: 1 ) )
139+
self.data.append( UnsafeBufferPointer( start: &v, count: 1 ) )
140140
}
141141
}
142142

143143
/**
144144
* Appends a `UInt32` value to the stream.
145145
*
146-
* - parameter uInt32: The `UInt32` value to append.
146+
* - parameter value: The `UInt32` value to append.
147147
*/
148148
@objc( appendUInt32: )
149-
public func append( uInt32: UInt32 )
149+
public func append( value: UInt32 )
150150
{
151151
self.synchronized
152152
{
153-
var value = uInt32.littleEndian
153+
var v = value.littleEndian
154154

155-
self.data.append( UnsafeBufferPointer( start: &value, count: 1 ) )
155+
self.data.append( UnsafeBufferPointer( start: &v, count: 1 ) )
156156
}
157157
}
158158

159159
/**
160160
* Appends a `UInt64` value to the stream.
161161
*
162-
* - parameter uInt64: The `UInt64` value to append.
162+
* - parameter value: The `UInt64` value to append.
163163
*/
164164
@objc( appendUInt64: )
165-
public func append( uInt64: UInt64 )
165+
public func append( value: UInt64 )
166166
{
167167
self.synchronized
168168
{
169-
var value = uInt64.littleEndian
169+
var v = value.littleEndian
170170

171-
self.data.append( UnsafeBufferPointer( start: &value, count: 1 ) )
171+
self.data.append( UnsafeBufferPointer( start: &v, count: 1 ) )
172172
}
173173
}
174174

175175
/**
176176
* Appends a float value to the stream.
177177
*
178-
* - parameter float: The float value to append.
178+
* - parameter value: The float value to append.
179179
*/
180180
@objc( appendFloat: )
181-
public func append( float: Float )
181+
public func append( value: Float )
182182
{
183183
self.synchronized
184184
{
185-
var value = float
185+
var v = value
186186

187-
self.data.append( UnsafeBufferPointer( start: &value, count: 1 ) )
187+
self.data.append( UnsafeBufferPointer( start: &v, count: 1 ) )
188188
}
189189
}
190190

191191
/**
192192
* Appends a double value to the stream.
193193
*
194-
* - parameter double: The double value to append.
194+
* - parameter value: The double value to append.
195195
*/
196196
@objc( appendDouble: )
197-
public func append( double: Double )
197+
public func append( value: Double )
198198
{
199199
self.synchronized
200200
{
201-
var value = double
201+
var v = value
202202

203-
self.data.append( UnsafeBufferPointer( start: &value, count: 1 ) )
203+
self.data.append( UnsafeBufferPointer( start: &v, count: 1 ) )
204204
}
205205
}
206206

207207
/**
208208
* Appends a boolean value to the stream.
209209
*
210-
* - parameter bool: The boolean value to append.
210+
* - parameter value: The boolean value to append.
211211
*/
212212
@objc( appendBool: )
213-
public func append( bool: Bool )
214-
{
215-
self.synchronized
216-
{
217-
self.append( uInt8: bool ? 1 : 0 )
218-
}
219-
}
220-
221-
/**
222-
* Appends a `UInt8` value to the stream.
223-
*
224-
* - parameter uInt8: The `UInt8` value to append.
225-
*/
226-
public func append( value: UInt8 )
227-
{
228-
self.synchronized
229-
{
230-
self.append( uInt8: value )
231-
}
232-
}
233-
234-
/**
235-
* Appends a `UInt16` value to the stream.
236-
*
237-
* - parameter uInt16: The `UInt16` value to append.
238-
*/
239-
public func append( value: UInt16 )
240-
{
241-
self.synchronized
242-
{
243-
self.append( uInt16: value )
244-
}
245-
}
246-
247-
/**
248-
* Appends a `UInt32` value to the stream.
249-
*
250-
* - parameter uInt32: The `UInt32` value to append.
251-
*/
252-
public func append( value: UInt32 )
253-
{
254-
self.synchronized
255-
{
256-
self.append( uInt32: value )
257-
}
258-
}
259-
260-
/**
261-
* Appends a `UInt64` value to the stream.
262-
*
263-
* - parameter uInt64: The `UInt64` value to append.
264-
*/
265-
public func append( value: UInt64 )
266-
{
267-
self.synchronized
268-
{
269-
self.append( uInt64: value )
270-
}
271-
}
272-
273-
/**
274-
* Appends a float value to the stream.
275-
*
276-
* - parameter float: The float value to append.
277-
*/
278-
public func append( value: Float )
279-
{
280-
self.synchronized
281-
{
282-
self.append( float: value )
283-
}
284-
}
285-
286-
/**
287-
* Appends a double value to the stream.
288-
*
289-
* - parameter double: The double value to append.
290-
*/
291-
public func append( value: Double )
292-
{
293-
self.synchronized
294-
{
295-
self.append( double: value )
296-
}
297-
}
298-
299-
/**
300-
* Appends a boolean value to the stream.
301-
*
302-
* - parameter bool: The boolean value to append.
303-
*/
304213
public func append( value: Bool )
305214
{
306215
self.synchronized
307216
{
308-
self.append( bool: value )
217+
self.append( value: value ? UInt8( 1 ) : UInt8( 0 ) )
309218
}
310219
}
311220

ColorSetKit/NSColor+ColorSetKit.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ import Cocoa
6464
*
6565
* - returns: The color object, if found.
6666
*/
67-
@objc class func from( colorSet name: String ) -> NSColor?
67+
@objc( colorFromColorSet: )
68+
class func fromColorSet( name: String ) -> NSColor?
6869
{
6970
if name.hasPrefix( "NS" )
7071
{

0 commit comments

Comments
 (0)