swift-corelibs-foundation | Foundation Project , providing core utilities | Web Framework library
kandi X-RAY | swift-corelibs-foundation Summary
kandi X-RAY | swift-corelibs-foundation Summary
The Foundation Project, providing core utilities, internationalization, and OS independence
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of swift-corelibs-foundation
swift-corelibs-foundation Key Features
swift-corelibs-foundation Examples and Code Snippets
Community Discussions
Trending Discussions on swift-corelibs-foundation
QUESTION
Question - What is the difference between Swift Foundation and standard library?
I know they are not in the same repository. Swift standard library and Swift Foundation.
My understanding is that Swift standard library is low level library that are support for core data types, array, etc... written in swift. And Swift Foundation is for higher level which are already included common utilities codes written in swift language. But my confusion is that why are the objective-c classes like NSArray are included in Foundation library? Can you explain me with more details?
...ANSWER
Answered 2020-May-31 at 17:50To understand what's going on here, first distinguish three things:
Swift library is the Swift native types, like String and Array.
Foundation is the Cocoa Objective-C basic set of types, like NSString and NSArray and NSDate and NSData.
Swift also contains an overlay library that shadows (without obscuring) types in the Foundation. For example, Date shadows NSDate, and Data shadows NSData. This makes the Cocoa Foundation a lot easier to use in Swift.
Note that there are two very different relations in which a Swift type can stand with respect to a Cocoa Objective-C type.
String and Array are completely independent native Swift types. They are bridged to NSString and NSArray respectively, but they exist without Foundation.
Data and Date are merely facades for NSData and NSDate respectively. If you import Swift but not Foundation, Data and Date are not even present.
Okay, so far so good. But this situation presents a quandary, because one would like to use Data and Date without the need for Foundation, in places like Linux that do not have it in the first place. Therefore, the project you have pointed to, https://github.com/apple/swift-corelibs-foundation, provides a backing for Data and Date (and so on) independent of Foundation. But if you are developing for iOS or MacOS you would never use it, because the real Foundation is present.
QUESTION
I've been investigating and trying to code a compact number format otherwise known as a short scale formatter or a humanizing big numbers into smaller ones in Swift.
I suddenly thought rather than trying to recode the wheel maybe Unicode
already solved this issue and saw that there is indeed some code to compact larger numbers.
In the open-source code for Apple Swift on Github there is a reference to compactdecimalformat.h
at:
In it, it refers to numberformatter.h; which I found a reference from Unicode ICU 67.1 at:
https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/numberformatter_8h.html
However, I am not sure how to use it. I've imported Darwin, but I am not sure how to actually call compactdecimalformat
or the public identifier DecimalFormat
I'd like to run some number tests against it to see if it is what I'm looking for in terms of compacting / short scaling numbers.
Thus my question is, how do you include and use the compactdecimalnumber.h file that comes as part of the Darwin import?
With thanks
edit: I think upon reading the code and comments the .h file only handles really big numbers?
...ANSWER
Answered 2020-May-22 at 06:00I don't think there is such formatter in Swift but you can subclass NumberFormatter and create your own CompactNumberFormatter if needed:
QUESTION
I'm working on an app that shows currencies with large numbers. To make it more user friendly it would be nice to show the numbers with letters, e.g:
$24,514,983,671 -> $24.5B // English
3,306,777.10 € -> 3,31 Mio. € // German
kr 23 000 000 -> kr 23 mill. // Norwegian
The numbers should have minimumSignificantDigits = 1 and maximumSignificantDigits = 3.
How should this be solved in Swift? Is there any library available?
It seems to be based on swift-corelibs-foundation: Github, but I can't see how to use it in my app.
Will I have to make the logic myself with localized translations? I have found an answer for using general abbreviations K/M/B for large numbers here: iOS convert large numbers to smaller format, but it does not solve the whole problem.
...ANSWER
Answered 2020-Feb-04 at 13:11You will have to implement your own solution, but it is not hard. One way to go would be to create two dictionaries where the key will be the Locale identifier and the value the translation:
QUESTION
When I try to use the struct URLRequest from Foundation, I get an error when compiling with swift 5.1.1. The same code works fine with swift 5.0.1.
Example: given file Foo.swift with content
...ANSWER
Answered 2019-Oct-29 at 11:24This is caused by a recent move of networking related objects into a new FoundationNetworking module. The new module does not exists on Darwin, so one must use preprocessor commands to make code work on all supported platforms:
QUESTION
I'm experiencing an issue with the Foundation struct URL's string initializer. I'll post some code from the repl below:
...ANSWER
Answered 2019-Oct-09 at 00:50It would appear to be a REPL issue and existed in 11.0, too. But if you print(testUrl1)
, you’ll see it really is set.
QUESTION
This is what I see in the documentation.
The NSCache class incorporates various auto-eviction policies, which ensure that a cache doesn’t use too much of the system’s memory. If memory is needed by other applications, these policies remove some items from the cache, minimizing its memory footprint.
But when I look into the source code: https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSCache.swift
I see nothing about it somehow deletes items, when under memory pressure. It only deletes items when you reach the cost limit.
I made a small test:
...ANSWER
Answered 2019-Sep-01 at 02:03First, and most importantly, swift-corelibs-foundation is not the Foundation from iOS and macOS:
This project, swift-corelibs-foundation, provides an implementation of the Foundation API for platforms where there is no Objective-C runtime. On macOS, iOS, and other Apple platforms, apps should use the Foundation that comes with the operating system. Our goal is for the API in this project to match the OS-provided Foundation and abstract away the exact underlying platform as much as possible.
Next, your test case does not carefully test NSCache
. Your Data
objects could be stored on the autorelease pool and not released. In this case that's not true, but it's the kind of thing you need to be very careful about when testing memory usage.
That said, I can't reproduce your issue. When I put this in an iOS app and run it on iOS 12, I see the kind of behavior you're probably expecting:
Big run-up in memory usage to ~1GB, at which point the cache is dumped as expected.
I also wasn't able to easily reproduce it on macOS (but I wasn't patient enough to let it crash, so it's possible it eventually would). You'll need to give a more precise example of where this crashes unexpectedly in order to diagnose why.
QUESTION
Recently ran into a crash in our app:
...ANSWER
Answered 2019-Jun-05 at 20:36I think you are right assuming that request
is nil
, when the error occurs. A similar problem is described here.
Since URLRequest.swift
, as defined in apple/swift-corelibs-foundation
that your cited will definitively crash if request is nil
, one cannot use it in this situation.
One alternative is definitively to use KVO, since func value(forKey key: String) -> Any?
can return nil
values, see here.
However, you can only use it, if the object, in which the function is called, adopted the NSKeyValueCoding
protocol, which is ensured if the object is a subclass of NSObject
, which I cannot tell from your code fragment.
But since you suggested this already in your question, did you try it?
QUESTION
I'm trying to build the Swift Foundation workspace in Xcode using the instructions, but the build fails as shown below:
I'm running Xcode 9.0.1
, Sierra 10.12.6
and Swift 4. I've also installed the Swift 4.0 toolchain.
Any help would be greatly appreciated.
...ANSWER
Answered 2018-Jan-23 at 09:32I downloaded the swift development toolchain and added it in xcode. I can now successfully build and run tests. Thanks Hamish :)
QUESTION
Consider a private CFLocaleKey
that is later bridged as an NSLocaleKey
(NSString
) for use internally with NSLocale
:
ANSWER
Answered 2017-Aug-08 at 14:07As of writing (August 8th, 2017), this currently is not possible with any version of Swift (3 or 4).
Without a header declaration, clang isn't sure how to map something in Swift back to C. @_silgen_name
and @_cdecl
work on functions, but not for variables.
This was confirmed by Jordan Rose, a Swift compiler engineer at Apple on Twitter.
tl;dr:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install swift-corelibs-foundation
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page