From a3faaeaa19cb263b63869b69209c8b71e091dd07 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 27 Oct 2022 14:33:51 +0200 Subject: [PATCH] Add NSString::write_to_file --- objc2/CHANGELOG_FOUNDATION.md | 1 + objc2/src/foundation/string.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/objc2/CHANGELOG_FOUNDATION.md b/objc2/CHANGELOG_FOUNDATION.md index 7f6d52269..2068eb094 100644 --- a/objc2/CHANGELOG_FOUNDATION.md +++ b/objc2/CHANGELOG_FOUNDATION.md @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). * Added `NSString::concat` and `NSString::join_path`. * Added `CGSize`, `CGPoint` and `CGRect` (just aliases to equivalent `NS`-types, but helps readability). +* Added `NSString::write_to_file`. ### Changed * **BREAKING**: `NSSize::new` no longer requires it's arguments to be diff --git a/objc2/src/foundation/string.rs b/objc2/src/foundation/string.rs index 0c0b4d982..d9b83e323 100644 --- a/objc2/src/foundation/string.rs +++ b/objc2/src/foundation/string.rs @@ -9,7 +9,7 @@ use core::slice; use core::str; use std::os::raw::c_char; -use super::{NSComparisonResult, NSCopying, NSMutableCopying, NSMutableString, NSObject}; +use super::{NSComparisonResult, NSCopying, NSError, NSMutableCopying, NSMutableString, NSObject}; use crate::rc::{autoreleasepool, AutoreleasePool, DefaultId, Id, Shared}; use crate::runtime::{Class, Object}; use crate::{extern_class, extern_methods, msg_send, msg_send_id, ClassType}; @@ -272,6 +272,15 @@ extern_methods!( // pub fn from_nsrange(range: NSRange) -> Id // https://developer.apple.com/documentation/foundation/1415155-nsstringfromrange?language=objc + + // TODO: Safety + #[sel(writeToFile:atomically:encoding:error:)] + pub unsafe fn write_to_file( + &self, + path: &NSString, + atomically: bool, + encoding: usize, + ) -> Result<(), Id>; } );