Class: NSError

Inherits:
Object show all
Defined in:
lib/cocoa/sugarcube-to_s/nserror.rb,
lib/ios/sugarcube-factories/nserror.rb,
lib/cocoa/sugarcube-localized/nserror.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.error(message = 'Error', options = {}) ⇒ Object

Examples:

NSError.error('just a simple error message')
NSError.error('just a simple error message',
  domain: 'foo',
  code: 255,
  userInfo: { 'object' => 'foo' }
)


10
11
12
13
14
15
16
17
18
# File 'lib/ios/sugarcube-factories/nserror.rb', line 10

def self.error(message='Error', options={})
  domain = options[:domain] || 'Error'
  code = options[:code] || 0
  info = { NSLocalizedDescriptionKey => message }
  if options[:userInfo]
    info.merge! options[:userInfo]
  end
  NSError.alloc.initWithDomain(domain, code: code, userInfo: info)
end

Instance Method Details

#localizedObject Also known as: _



3
4
5
# File 'lib/cocoa/sugarcube-localized/nserror.rb', line 3

def localized
  localizedDescription
end

#to_sObject



3
4
5
6
7
8
# File 'lib/cocoa/sugarcube-to_s/nserror.rb', line 3

def to_s
  "#<#{self.class.to_s}:0x#{self.object_id.to_s(16)}, "+
    "description=#{self.localizedDescription.inspect}, code=#{code}, "+
    "domain=#{domain.inspect}, userInfo=#{userInfo.inspect}"+
   ">"
end