Class: NSData
- Defined in:
- lib/ios/sugarcube-nsdata/nsdata.rb,
lib/osx/sugarcube-nsdata/nsdata.rb,
lib/cocoa/sugarcube-files/nsdata.rb,
lib/cocoa/sugarcube-base64/nsdata.rb,
lib/cocoa/sugarcube-nsdata/nsdata.rb
Class Method Summary collapse
-
.from_base64(base64_data) ⇒ Object
factory method to convert a base64 string into NSData.
- .read_from(path_or_url) ⇒ Object
Instance Method Summary collapse
- #nsimage ⇒ NSImage
-
#nsstring(encoding = NSUTF8StringEncoding) ⇒ NSString
converts NSData into an NSString using any encoding, default is UTF8.
-
#to_base64 ⇒ Object
converts an NSData instance into a base64 string.
- #uiimage(scale = nil) ⇒ UIImage
- #write_to(path_or_url, atomically = true) ⇒ Object
Class Method Details
Instance Method Details
#nsimage ⇒ NSImage
4 5 6 |
# File 'lib/osx/sugarcube-nsdata/nsdata.rb', line 4 def nsimage return NSImage.alloc.initWithData(self) end |
#nsstring(encoding = NSUTF8StringEncoding) ⇒ NSString
converts NSData into an NSString using any encoding, default is UTF8
5 6 7 |
# File 'lib/cocoa/sugarcube-nsdata/nsdata.rb', line 5 def nsstring(encoding=NSUTF8StringEncoding) return NSString.alloc.initWithData(self, encoding: encoding) end |
#to_base64 ⇒ Object
TODO:
Support NSDataBase64EncodingOptions options - easy to add, but I want
converts an NSData instance into a base64 string. to add specs, too, and a hash format (e.g. line_length: 64 => NSDataBase64Encoding64CharacterLineLength).
7 8 9 |
# File 'lib/cocoa/sugarcube-base64/nsdata.rb', line 7 def to_base64 self.base64EncodedStringWithOptions(0) end |
#uiimage(scale = nil) ⇒ UIImage
4 5 6 7 8 9 10 |
# File 'lib/ios/sugarcube-nsdata/nsdata.rb', line 4 def uiimage(scale=nil) if scale return UIImage.imageWithData(self, scale:scale) else return UIImage.imageWithData(self) end end |
#write_to(path_or_url, atomically = true) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cocoa/sugarcube-files/nsdata.rb', line 18 def write_to(path_or_url, atomically=true) case path_or_url when NSURL self.writeToURL(path_or_url, atomically: atomically) when NSString self.writeToFile(path_or_url, atomically: atomically) else false end end |