1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # The Foundation Kit provides basic Objective-C classes and structures
18 module foundation
is ldflags
"-framework Foundation"
21 #import <Foundation/Foundation.h>
24 # Base of the Foundation framework class hierarchy
25 extern class NSObject in "ObjC" `{ NSObject * `}
28 # String of the Foundation Kit
30 # Created using `Text::to_nsstring
`.
31 extern class NSString in "ObjC" `{ NSString * `}
35 new nil
in "ObjC" `{ return nil; `}
37 # Get an UTF8 encoded `char
*` copy of `self`
38 fun utf8_string: CString in "ObjC" `{ return (char *)[self UTF8String]; `}
40 redef fun to_s
do return utf8_string
.to_s_with_copy
44 # Get a `NSString` from `self` with the specified `length`
45 fun to_nsstring
(length
: Int): NSString in "ObjC" `{
46 return [[NSString alloc] initWithBytes:self
48 encoding:NSUTF8StringEncoding];
53 # Get a `NSString` from `self`
54 fun to_nsstring
: NSString do return to_cstring
.to_nsstring
(byte_length
)
57 # Wrapper of byte buffers
58 extern class NSData in "ObjC" `{ NSData * `}
60 # Pointer to contained data
61 fun bytes: CString in "ObjC" `{ return (char*)self.bytes; `}
63 # Number of bytes containted in `self`
64 fun length
: Int in "ObjC" `{ return self.length; `}
66 redef fun to_s do return bytes.to_s_with_copy_and_length(length)
70 extern class NSError in "ObjC" `{ NSError * `}
72 # Wraps: `[self initWithDomain:(NSString)domain code:(NSInteger)code userInfo:(NSDictionary)dict]`
73 #new init_with_domain_code_user_info(domain: NSString, code: Int, dict: NSDictionary) in "ObjC" `{
74 # return [[NSError alloc] initWithDomain: domain code: code userInfo: dict];
77 # Wraps: `NSError.domain`
78 fun domain
: NSString in "ObjC" `{
82 # Wraps: `NSError.code`
83 fun code
: Int in "ObjC" `{
87 # Wraps: `NSError.userInfo`
88 #fun user_info: NSDictionary in "ObjC" `{
89 # return [self userInfo];
92 # Wraps: `NSError.localizedDescription`
93 fun localized_description
: NSString in "ObjC" `{
94 return [self localizedDescription];
97 # Wraps: `NSError.localizedFailureReason`
98 fun localized_failure_reason
: NSString in "ObjC" `{
99 return [self localizedFailureReason];
102 # Wraps: `NSError.localizedRecoverySuggestion`
103 fun localized_recovery_suggestion
: NSString in "ObjC" `{
104 return [self localizedRecoverySuggestion];
107 # Wraps: `NSError.localizedRecoveryOptions`
108 #fun localized_recovery_options: NSArray in "ObjC" `{
109 # return [self localizedRecoveryOptions];
112 # Wraps: `NSError.recoveryAttempter`
113 fun recovery_attempter
: NSObject in "ObjC" `{
114 return [self recoveryAttempter];
117 # Wraps: `NSError.helpAnchor`
118 fun help_anchor
: NSString in "ObjC" `{
119 return [self helpAnchor];
123 # Path to a specific node in a tree of nested array collections
124 extern class NSIndexPath in "ObjC" `{ NSIndexPath * `}
127 # Wraps: `[self initWithIndex
:(NSUInteger)index
]`
128 new init_with_index(index: Int) in "ObjC" `{
129 return [[NSIndexPath alloc
] initWithIndex
: index
];
132 # Wraps: `NSIndexPath.length
`
133 fun length: Int in "ObjC" `{
134 return [self length
];
137 # Wraps: `[self indexPathByAddingIndex
:(NSUInteger)index
]`
138 fun index_path_by_adding_index(index: Int): NSIndexPath in "ObjC" `{
139 return [self indexPathByAddingIndex
: index
];
142 # Wraps: `[self indexPathByRemovingLastIndex
]`
143 fun index_path_by_removing_last_index: NSIndexPath in "ObjC" `{
144 return [self indexPathByRemovingLastIndex
];
147 # Wraps: `[self indexAtPosition
:(NSUInteger)position
]`
148 fun index_at_position(position: Int): Int in "ObjC" `{
149 return [self indexAtPosition
: position
];
153 # Interface to the defaults system for an app to customize its behavior to match a user's preferences
154 extern class NSUserDefaults in "ObjC" `{ NSUserDefaults * `}
157 # Wraps: `[NSUserDefaults standardUserDefaults]`
158 new standard_user_defaults
in "ObjC" `{
159 return [NSUserDefaults standardUserDefaults];
162 # Wraps: `[NSIndexPath stringForKey:]`
163 fun string_for_key
(key
: NSString): NSString in "ObjC" `{
164 return [self stringForKey: key];
167 # Wraps: `[NSIndexPath setObject: forKey:]`
168 fun set_object
(value
: NSObject, default_name
: NSString)
170 [self setObject:value forKey:default_name];