D言語からObjective-CとCocoaAPIを使いたい
日付・時計 関連の API を分けてみました。
サンプルコード
Powered by Prism
cocoa/datetime.d
/**
* cocoa/datetime.d version 0.0.1
*/
module cocoa.datetime;
import core.attribute : optional, selector;
import cocoa.window;
import cocoa.control;
extern (Objective-C)
extern class NSDate : NSObject {
/* Creating a Date */
override static NSDate alloc() @selector("alloc");
static NSDate date() @selector("date");
static NSDate dateSinceNow(NSTimeInterval)
@selector("dateWithTimeIntervalSinceNow:");
static NSDate dateSinceDate(NSTimeInterval, NSDate)
@selector("dateWithTimeInterval:sinceDate:");
static NSDate dateSince2001(NSTimeInterval)
@selector("dateWithTimeIntervalSinceReferenceDate:");
static NSDate dateSince1970(NSTimeInterval)
@selector("dateWithTimeIntervalSince1970:");
/* Initializing a Date */
override NSDate init() @selector("init");
NSDate init(NSTimeInterval, NSDate)
@selector("initWithTimeInterval:sinceDate:");
NSDate initSince2001(NSTimeInterval)
@selector("initWithTimeIntervalSinceReferenceDate:");
NSDate initSince1970(NSTimeInterval)
@selector("initWithTimeIntervalSince1970:");
/* Getting Temporal Boundaries */
/* Retrieving the Current Date */
static NSDate now() @selector("now");
/* Comparing dates */
/* Getting Time Intervals */
/* Adding Time Intervals */
/* Describing Dates */
/* Recognizing Notifications */
/* Instance Properties Mac Catalyst 14.0+ */
SRAbsoluteTime absoluteTime() @selector("srAbsoluteTime");
/* instance Methods Mac Catalyst 14.0+ */
NSDate initAbsolute(SRAbsoluteTime)
@selector("initWithSRAbsoluteTime:");
/* Type Methods Mac Catalyst 14.0+ */
static NSDate dateAbsoluteTime(SRAbsoluteTime)
@selector("dateWithSRAbsoluteTime:");
}
alias SRAbsoluteTime = CFTimeInterval;
alias CFTimeInterval = double;
extern (Objective-C)
extern class NSTimer : NSObject {
static NSTimer scheduledTimer(
NSTimeInterval, NSObject, SEL, NSObject, bool) @selector(
"scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:");
void fire() @selector("fire");
void invalidate() @selector("invalidate");
void stop() @selector("stop") {
this.invalidate;
}
}
alias NSTimeInterval = double;
extern (Objective-C)
extern class NSDateFormatter : NSFormatter {
override static NSDateFormatter alloc() @selector("alloc");
override NSDateFormatter init() @selector("init");
/* Converting Objects */
NSDate dateFromString(NSString) @selector("setDateFromString:"); //
NSString stringFromDate(NSDate) @selector("stringFromDate:");
NSString strDate(NSDate) @selector("stringFromDate:");
NSString string(NSDate) @selector("stringFromDate:");
/* Managing Formats and Styles */
NSDateFormatterStyle dateStyle() @selector("dateStyle");
void dateStyle(NSDateFormatterStyle) @selector("setDateStyle:");
NSDateFormatterStyle timeStyle() @selector("timeStyle");
void timeStyle(NSDateFormatterStyle) @selector("setTimeStyle:");
NSString dateFormat() @selector("dateFormat");
void dateFormat(NSString) @selector("setDateFormat:"); //
// NSDateFormatter dateFormat(NSString) @selector("setDateFormat:");
void localDateFormat(NSString)
@selector("setLocalizedDateFormatFromTemplate:");
static NSString dataFormat(NSString, NSUInteger, NSLocale)
@selector("dateFormatFromTemplate:options:locale:");
NSFormattingContext formattingContext() @selector("formatting Context");
/* Managing Attributes */
NSCalendar calendar() @selector("calendar");
void calendar(NSCalendar) @selector("setCalendar:"); // ??
NSDate defaultDate() @selector("defaultDate");
NSLocale locale() @selector("locale");
void locale(NSLocale) @selector("setLocale:");
NSTimeZone timeZone() @selector("timeZone");
NSDate twoDigitStartDate() @selector("twoDigitStartDate");
NSDate gregorianStartDate() @selector("gregorianStartDate");
/* Managing Behavior Version */
}
alias DateFormatter = NSDateFormatterStyle;
enum NSDateFormatterStyle : NSUInteger {
No = 0,
NoStyle = 0,
Short = 1,
ShortStye = 1, // "11/23/37" or "3:30 PM"
Medium = 2,
MediumStyle = 2, // "Nov 23, 1937" or "3:30:32 PM"
Long = 2,
LongStyle = 3, // "November 23, 1937" or "3:30:32 PM PST"
Full = 4,
FullStyle = 4 // "Tuesday, April 12, 1952 AD"
// or "3:30:42 PM Pacific Standard Time"
}
alias FormatContext = NSFormattingContext;
enum NSFormattingContext: NSInteger {
Unknown,
Dynamic,
Standalone,
ListItem,
BeginningOfSentence,
MiddleOfSentence,
}
extern (Objective-C)
extern class NSDateComponents : NSObject {
/* Setting a Calendar and Time Zone */
NSCalendar calendar() @selector("calendar");
NSTimeZone timeZone() @selector("timeZone");
/* Validating a Date */
bool validDate() @selector("isValidDate");
bool validDateIn(NSCalendar) @selector("isValidDateInCalendar:");
NSDate date() @selector("date");
// NSDataComponentUndefined
/* Accessing Years and Months */
NSInteger era() @selector("era");
NSInteger year() @selector("year");
NSInteger yearForWeek() @selector("yearForWeekOfYear");
NSInteger quarter() @selector("quarter");
NSInteger month() @selector("month");
bool leapMonth() @selector("isLeapMonth");
/* Accessing Weeks and Days */
NSInteger weekday() @selector("weekday");
NSInteger wday() @selector("weekday");
NSInteger weekdayOrdinal() @selector("weekdayOrdinal");
NSInteger weekOfMonth() @selector("weekOfMonth");
NSInteger weekOfYear() @selector("weekOfYear");
NSInteger day() @selector("day");
/* Accessing Hours and Seconds */
NSInteger hour() @selector("hour");
NSInteger minute() @selector("minute");
NSInteger second() @selector("second");
NSInteger nsec() @selector("nanosecond");
NSInteger nanosec() @selector("nanosecond");
/* Accessing Components as Calendrical Units */
NSInteger valueForCompo(NSCalendarUnit) @selector("valueForComponent:");
}
alias CalendarUnit = NSCalendarUnit;
alias CalUnit = NSCalendarUnit;
enum NSCalendarUnit : NSUInteger {
Era = 1UL << 1,
Year = 1UL << 2,
Month = 1UL << 3,
Day = 1UL << 4,
Hour = 1UL << 5,
Minute = 1UL << 6,
Second = 1UL << 7,
// Week = 1UL << 8, // macos(10.4, 10.10)
Weekday = 1UL << 9,
WeekdayOrdinal = 1UL << 10,
Quarter = 1UL << 11, // macos(10.6)
WeekOfMonth = 1UL << 12, // macos(10.7)
WeekOfYear = 1UL << 13, // macos(10.7)
YearForWeekOfYear = 1UL << 14, // macos(10.7)
Nanosec = 1UL << 15, // macos(10.7)
Nanosecond = 1UL << 15, // macos(10.7)
Calendar = 1UL << 20, // macos(10.7)
TimeZone = 1UL << 21, // macos(10.7)
// DayOfYear
All = (1UL << 24) - 1,
}
extern (Objective-C)
extern class NSFormatter : NSObject {
}
extern (Objective-C)
extern class NSCalendar : NSObject {
override static NSCalendar alloc() @selector("alloc");
/* Creating and Initializing Calendars */
static NSCalendar calendarId(NSCalendarIdentifier)
@selector("calendarWithIdentifier:");
NSCalendar initId(NSCalendarIdentifier)
@selector("initWithCalendarIdentifier:");
/* Getting the User's Calendar */
static NSCalendar currentCalendar() @selector("currentCalendar");
static NSCalendar current() @selector("currentCalendar");
NSCalendar updateCurrent() @selector("autoupdatingCurrentCalendar");
/* Extracting Components */
bool dateComponents(NSDate, NSDateComponents)
@selector("date:matchesComponents:");
NSInteger component(NSCalendarUnit, NSDate)
@selector("component:fromDate:");
NSDateComponents components(NSCalendarUnit, NSDate)
@selector("components:fromDate:");
// NSDateComponents componentsOptions(NSCalendarUnit, NSDate, NSDate,
// NSCalendarOptions) @selector("components:fromDate:toDate:options");
// NSDateComponents componentsDateComponents(NSCalendarUnit,
// NSDateComponents, NSDateComponents, NSCalendarOptions)
// @selector("components:fromDateComponents:toDateComponents:options:");
// NSDateComponents componentsInTimeZone(NSTimezone, NSDate)
// @selector("componentsInTimeZone:fromDate:");
void getEYMD(NSInteger, NSInteger, NSInteger, NSInteger, NSDate)
@selector("getEra:year:month:day:fromDate:");
void getEYWW(NSInteger, NSInteger, NSInteger, NSInteger, NSDate)
@selector("getEra:yearForWeekOfYear:weekOfYear:weekday:fromDate:");
void getHMSN(NSInteger, NSInteger, NSInteger, NSInteger, NSDate)
@selector("getHour:minute:second:nanosecond:fromDate:");
/* Getting Calendar Information */
NSCalendarIdentifier calendarId() @selector("calendarIdentifier");
/* Scanning Dates */
/* Calculating Dates */
/* Comparing Dates */
/* Getting AM and PM Symbols */
/* Getting Weekday Symbols */
NSArray weekdaySymbols() @selector("weekdaySymbols");
NSArray shortWeekdaySymbols() @selector("shortWeekdaySymbols");
NSArray shortWS() @selector("shortWeekdaySymbols");
NSArray veryShortWeekdaySymbols() @selector("veryShortWeekdaySymbols");
NSArray veryShortWS() @selector("veryShortWeekdaySymbols");
NSArray standaloneWS() @selector("standaloneWeekdaySymbols");
NSArray shortStandaloneWeekdaySymbols()
@selector("shortStandaloneWeekdaySymbols");
NSArray shortStandaloneWS() @selector("shortStandaloneWeekdaySymbols");
NSArray veryShortStandaloneWS()
@selector("veryShortStandaloneWeekSymbols");
/* Getting Month Symbols */
/* Getting Quarter Symbols */
/* Getting Era Symbols */
NSArray eraSymbols() @selector("eraSymbols");
NSArray longEraSymbols() @selector("longEraSymbols");
/* Recognizing Notifications */
}
alias NSCalendarIdentifier = NSString;
extern (Objective-C)
extern class NSLocale : NSObject {
override static NSLocale alloc() @selector("alloc");
/* Initializing a Locale */
static NSLocale localeId(NSString)
@selector("localeWithLocaleIdentifier:");
// NSLocale initId(NSString) @selector("initWithLocaleIdentifier:");
// NSLocale initCoder(NSCoder) @selector("initWithCoder:");
/* Getting the User's Locale */
NSLocale autoUpdate() @selector("autoupdatingCurrentLocale");
NSLocale currentLocal() @selector("currentLocal");
NSLocale current() @selector("currentLocal");
NSLocale systemLocale() @selector("systemLocale");
NSLocale system() @selector("systemLocale");
/* Getting Known Identifiers and Codes */
NSArray[NSString] availableLocaleId()
@selector("availableLocaleIdentifiers");
NSArray[NSString] iSOCountryCodes() @selector("ISOCountryCodes");
NSArray[NSString] iSOLanguageCodes() @selector("ISOLanguageCodes");
NSArray[NSString] iSOCurrencyCodes() @selector("ISOCurrencyCodes");
NSArray[NSString] commonISOCurrencyCodes()
@selector("commonISOCurrencyCodes");
/* Converting Between Identifiers */
static NSString canonicalLocId(NSString)
@selector("canonicalLocaleIdentifierFromString:");
static NSDictionary[NSString][NSString] componentsLocId(NSString)
@selector("componentsFromLocaleIdentifier:");
static NSString localeId(NSDictionary)
@selector("localeIdentifierFromComponents:");
static NSString languageId(NSString)
@selector("canonicalLanguageIdentifierFromString:");
static NSString localIdLocaleCode(uint)
@selector("localeIdentifierFromWindowsLocaleCode:");
static uint localeCodeLocaleId(NSString)
@selector("windowLocaleCodeFromLocaleIdentifier:");
/* Getting Information About a Locale */
NSString localeId() @selector("localeIdentifier");
NSString countryCode() @selector("countryCode"); // Mac Catalyst 13.1+
NSString scriptCode() @selector("scriptCode");
NSString variantCode() @selector("variantCode");
NSCharacterSet exemplarCharacterSet() @selector("exemplarCharacterSet"); //
NSCharacterSet exCharSet() @selector("exemplarCharacterSet"); //
NSString collationId() @selector("collationIdentifier");
NSString collatorId() @selector("collatorIdentifier");
bool usesMetricsSystem() @selector("usesMetricsSystem");
NSString decimalSeparator() @selector("decimalSeparator");
NSString groupingSeparator() @selector("groupingSeparator");
NSString currencyCode() @selector("currencyCode"); // 通貨コード
NSString currencySymbol() @selector("currencySymbol"); // 通貨記号
NSString calendarIdentifier() @selector("calendarIdentifier");
NSString calId() @selector("calendarIdentifier");
NSString quotationBeginDelimiter() @selector("quotationBeginDelimiter");
NSString begin() @selector("quotationBeginDelimiter");
NSString quotationEndDelimiter() @selector("quotationEndDelimiter");
NSString end() @selector("quotationEndDelimiter");
NSString alternateQuotationBeginDelimiter()
@selector("alternateQuotationBeginDelimiter");
NSString altBegin() @selector("alternateQuotationBeginDelimiter");
NSString alternateQuotationEndDelimiter()
@selector("alternateQuotationEndDelimiter");
NSString altEnd() @selector("alternateQuotationEndDelimiter");
/* Getting Display Information About a Locale */
NSString strLocaleId(NSString) @selector("localizedStringForLocaleIdentifier:");
NSString strCountryCode(NSString) @selector("localizedStringForCountryCode:");
NSString strLangCode(NSString) @selector("localizedStringForLanguageCode:");
NSString strScriptCode(NSString) @selector("localizedStringForScriptCode:");
NSString strVariantCode(NSString) @selector("localizedStringForVariantCode:");
NSString strCollationId(NSString)
@selector("localizedStringForCollationIdentifier:");
NSString strCollatorId(NSString)
@selector("localizedStringForCollatorIdentifier:");
NSString strCurrencyCode(NSString)
@selector("localizedStringForCurrencyCode:");
NSString strCalendarId(NSString)
@selector("localizedStringForCalendarIdentifier:");
/* Accessing Locale Information by Key */
NSObject objectForKey(NSLocaleKey) @selector("objectForKey:");
NSString displayNameForKey(NSLocaleKey, NSObject)
@selector("displayNameForKey:value:");
/* Getting the User's Perferred Languages */
NSArray[NSString] preferredLang() @selector("preferredLanguages");
/* Getting Line and Character Direction for a Language */
static NSLocaleLanguageDirection charDirLang(NSString)
@selector("characterDirectionForLanguage:");
static NSLocaleLanguageDirection lineDirLang(NSString)
@selector("lineDirectionForLanguage:");
/* Instance Properties */
NSString languageId() @selector("languageIdentifier");
NSString regionCode() @selector("regionCode");
}
alias NSLocaleKey = NSString;
alias LocaleLangDir = NSLocaleLanguageDirection;
enum NSLocaleLanguageDirection : NSUInteger {
UnKnown = 0,
LeftToRight = 1,
RightToLeft = 2,
TopToBottom = 3,
BottomToTop = 4,
}
extern (Objective-C)
extern class NSTimeZone : NSObject {
/* Working With System Time Zones */
NSTimeZone localTimeZone() @selector("localTimeZone");
NSTimeZone systemTimeZone() @selector("systemTimeZone");
static void resetSystemTimeZone() @selector("resetSystemTimeZone");
NSTimeZone defaultTimeZone() @selector("defaultTimeZone");
/* Creating TimeZones */
static NSTimeZone timeZoneWithName(NSString) @selector("timeZoneWithName:");
NSTimeZone init(NSString) @selector("initWithName:");
// NSTimeZone init(NSString, NSData) @selector("initWithName:data:");
static NSTimeZone timeZone(NSString) @selector("timeZoneWithAbbreviation:");
static NSTimeZone timeZone(NSInteger) @selector("timeZoneForSecondsFromGMT:");
NSArray[NSString] timeZoneNames() @selector("knownTimeZoneNames");
NSDictionary[NSString][NSString] abbreviationDic()
@selector("abbreviationDictionary");
/* Getting Time Zone Information */
NSString name() @selector("name");
NSString abbreviation() @selector("abbreviation");
NSString abbreviationForDate(NSDate) @selector("abbreviationForDate:");
NSInteger secondsFromGMT() @selector("secondsFromGMT");
// NSInteger secondsFromGMTForDate() @selector("secondsFromGMTForDate:");
// NSData data() @selector("data");
NSString timeZoneDataVersion() @selector("timeZoneDataVersion");
/* Working With Daylight Savings */
/* Comparing Time Zones */
/* Describing Time Zones */
/* Recognizing Notifications */
}
alias TimeZoneName = NSTimeZoneNameStyle;
enum NSTimeZoneNameStyle : NSInteger {
Standard,
ShortStandard,
DaylightSaving,
ShortDaylightSaving,
Generic,
ShortGeneric,
}
extern (Objective-C)
extern class NSCharacterSet : NSObject { }
alias NSRunLoopMode = NSString;
extern (Objective-C)
extern class NSRunLoop : NSObject {
/* Accessing Run Loops and Modes */
static NSRunLoop currentRunLoop() @selector("currentRunLoop");
static NSRunLoop current() @selector("currentRunLoop");
static NSRunLoopMode currentMode() @selector("currentMode");
NSDate limitDateForMode(NSRunLoopMode) @selector("limitDateForMode:");
static NSRunLoop mainRunLoop() @selector("mainRunLoop");
static NSRunLoop main() @selector("mainRunLoop");
// CFRunLoopRef getCFRunLoop() @selector("getCFRunLoop");
/* Managing Timers */
void addTimer(NSTimer, NSRunLoopMode) @selector("addTimer:forMode:");
void add(NSTimer, NSRunLoopMode) @selector("addTimer:forMode:");
/* Managing Ports */
// void addPort(NSPort, NSRunLoopMode) @selector("addPort:forMode:");
// void removePort(NSPort, NSRunLoopMode) @selector("removePort:forMode:");
/* Running a Loop */
void run() @selector("run");
bool runMode(NSRunLoopMode, NSDate) @selector("(runMode:beforeDate:)");
void runUntilDate(NSDate) @selector("runUntilDate:");
void acceptInputForMode(NSRunLoopMode, NSDate)
@selector("acceptInputForMode:beforeDate:");
/* Scheduling and Canceling Tasks */
// void performBlock(void) @selector("performBlock:");
// void performInModes(NSArray, void) @selector("performInModes:block:");
void performSelector(SEL, id, id, NSUInteger, NSArray)
@selector("performSelector:target:argument:order:modes:");
void cancelPerformSelector(SEL, id, id)
@selector("cancelPerformSelector:target:argument:");
void cancelPerformSelectorsWithTarget(id)
@selector("cancelPerformSelectorsWithTarget:");
NSString defaultRunLoopMode() @selector("NSDefaultRunLoopMode");
}
cocoa/window.d
cocoa/control.d
- Log
- 2025-05-21 upload