Coder Social home page Coder Social logo

pureswift / swiftfoundation Goto Github PK

View Code? Open in Web Editor NEW
627.0 32.0 52.0 1.45 MB

Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

License: MIT License

Swift 100.00%
swift apple-foundation protocol-oriented cross-platform standard-library

swiftfoundation's Introduction

SwiftFoundation

Swift Platforms Release License Build Status

Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library.

Goals

  • Provide a cross-platform interface that mimics Apple's Foundation framework.
  • Provide a POSIX-based implementation for maximum portability.
  • Rewrite Foundation with Protocol-Oriented Programming principals.
  • Long-term Pure Swift replacement for the Cocoa frameworks.

Problems with Apple's Foundation

  • Objective-C - Apple's Foundation is an old API designed for Objective-C. While it works great (on Apple's platforms) and has a nice API for Objective-C programming, when imported into Swift, you can see the shortcomings of its 20+ year old API.
  • Unimplemented - The open source version of Apple's Foundation is severly lacking implementation. Most methods are marked with NSUnimplemented(). Only a small subset of Foundation based on CoreFoundation is implemented (e.g. NSArray, NSString, NSDictionary). Basic Functionality like JSON, Base64, and even HTTP requests are not implemented.
  • Portability - Since Apple's Foundation is backed by CoreFoundation, the only supported platforms are currently Linux, Darwin, and (potentially) Windows. Supporting other platforms (e.g. ARM Linux, BSD, SunOS) would require changes to the CoreFoundation codebase, written in C, which is not good for a long term Swift base library. We want all of our code to be understood by any Swift programmer.
  • Protocol Oriented Programming - Perhaps the biggest reason to use this library, is to break free from the old Object-Oriented Programming paradigms. Swift structures and protocols free you from pointers and memory management, along with bugs related to multithreaded environments. Creating structs for basic types like Date and UUID allows you to use let and var correctly. Structs also bring huge performance improvements since the compiler can perform more optimizations and doesn't have to create all the metadata needed for the Swift class runtime.

Targeted Platforms

Implemented

To see what parts of Foundation are implemented, just look at the unit tests. Completed functionality will be fully unit tested. Note that there is some functionality that is written as a protocol only, that will not be included on this list.

  • Base64
  • Data
  • Date
  • FileManager
  • JSON
  • RegularExpression (POSIX, not ICU)
  • Thread
  • URL
  • UUID

License

This program is free software; you can redistribute it and/or modify it under the terms of the MIT License.

swiftfoundation's People

Contributors

colemancda avatar davidask avatar dwarfland avatar leberwurstsaft avatar lvscar avatar nvzqz avatar ricardoherrera-santex avatar xai3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftfoundation's Issues

PureSwift Unit Tests

UnitTests based on Foundation should be moved to FoundationUnitTests. A new Pure Swift (Linux Compatible) Unit Tests module should be written to support unit tests on Linux.

Add DataConvertible protocol

init?(data: Data)
func toData() -> Data

The difference between this and ByteValueType is that the initializer is fallible and only supports Data.

Not really an issue

Hey man! I really liked this. I saw you forked my HTTP Server / Web Framework. Really enjoying this pure swift experiment. I see you have done a lot of similar work like, regular expressions, base64, etc.. This is really cool. I'm going to take a closer look later. It would be very interesting to have a centralized solution for this new "problem" of having code that runs on Linux as well. Willing to contribute to this!

Talking about another matter that it's very important, as well. I think it was you who did a post about using pure swift frameworks in command line applications by faking a bundle, was it? Is there another way? Swift not having a stable ABI sucks, and they (apple) have no clue when it'll happen.

Having some sort of package management like NPM and the likes would be awesome too, because the current ones (cocoapod, carthage) aren't doing the trick. Will they ever?

Sorry for using an issue to contact here. Is there a better way to contact another user in github?

Failed to compile `SwiftFoundation/Thread.swift`.

On 713b3ce:

First, not found CUUID.

SwiftFoundation/Sources/SwiftFoundation/UUID.swift:14:12: error: no such module 'CUUID'
    import CUUID
           ^

Edited Package.swift fixing the above error:

--- a/Package.swift
+++ b/Package.swift
@@ -11,7 +11,8 @@ let package = Package(
     ],
     dependencies: [
         .Package(url: "https://github.com/PureSwift/CStatfs.git", majorVersion: 1),
-        .Package(url: "https://github.com/PureSwift/CJSONC.git", majorVersion: 1)
+        .Package(url: "https://github.com/PureSwift/CJSONC.git", majorVersion: 1),
+        .Package(url: "https://github.com/PureSwift/CUUID.git", majorVersion: 1)
     ],
     exclude: ["Xcode", "Carthage"]
 )

Then failed to compile SwiftFoundation/Thread.swift:

``
src/SwiftFoundation/Sources/SwiftFoundation/Thread.swift:30:54: error: va$
ue of type 'Unmanaged<Thread.Closure>' has no member 'toOpaque'
let pointer = UnsafeMutablePointer(holder.toOpaque())
^~~~~~ ~~~~~~~~
src/SwiftFoundation/Sources/SwiftFoundation/Thread.swift:89:65: error: ca$
not convert value of type 'UnsafeMutablePointer' (aka 'UnsafeMutablePoint$
r<()>') to expected argument type 'OpaquePointer'
let unmanaged = Unmanaged<Thread.Closure>.fromOpaque(arg!)
~~~^

Be more modular

I'm looking for a good foundation-free JSON serializer and came upon PureSwift's, which has the barebones - exactly what I need. However, including the entire SwiftFoundation project is overkill if I just want JSON.

I propose to split all the large sections into separate repositories, and then this repository would just be the core that links them together and conforms the types to the necessary (probably FoundationConvertible) protocols. This might be a pain to do right now, but in the long run it's a much better solution.

Add Apple Foundation compatibility

Motivation

Apple has finally implemented Pure Swift value types for Foundation in Swift 3.0, but there are some issues with this:

  • Only a subset of types like Date are truly value type structs, the rest are structs, but backed by a reference type.
  • JSON is still AnyObject, not an enum
  • OSS Foundation is huge, will still have the CoreFoundation codebase, and it will still keep the NS* classes. This is not desirable for a Pure Swift portable library.
  • With Xcode, SwiftFoundation is a PITA to use because the types conflict with the new Foundation value types, which are imported implicitly.
  • They have only implemented this as a Swift addition in Darwin, the Linux support is still lacking, hence making this project still necessary.
  • This project provides a lot of functionality that OSS Foundation does not provide.
  • The compiled binary for this project is tiny compared to OSS Foundation.
  • OSS Foundation still depends on non-posix C libraries like CoreFoundation
  • Not as portable as SwiftFoundation because it's not truly Pure Swift.

Solution

  • Make conflicting types only compile on Linux. On Darwin we will remove the implementation of conflicting types, and make any additions extensions (e.g. RawRepresentable for UUID).
  • Update APIs to have to mirror the Darwin APIs
  • Keep all additions (e.g. HTTP.StatusCode, Null, JSON.Value) for both platforms.
  • Remove FoundationConvertible since ReferenceConvertible exists.

Include documentation in Git Repo

I know that there's a shell script to generate documentation, but it would be great to have it checked into git for developers browsing around.

problems in NSJSONSerialization

Hi,

I think as it currently stands, there are a couple of issues in NSJSONSerialization:

l. 160

self = JSON.Value.Number(JSON.Number(rawValue: Int(value))!)

will make any JSON Number an Int ... even if it is e.g. a Double

Compilation under Windows

Hey,

this is not really an issue but more a feature. I want to implement a cross platform (macos, iOS, Windows, Linux) tool and need some JSON de-serialization and file management. Currently I think about which library I want to use. My main question is if it is generally possible to compile Swift foundation under Windows since the OS is not listed in your readme.

Date Formatter Support?

Hey folks, I'm working on a project that requires DateFormatter support. Is this on the roadmap for this project? If it's not, is this feature something you'd accept in a contribution?

'POSIXError' does not conform to 'ErrorType'

I get this error when trying to compile on OSX with the latest swift 2.2 dec 31 snapshot.

Compiling Swift Module 'SwiftFoundation' (51 sources)
/SwiftFoundationExample/Packages/SwiftFoundation-1.1.0/Sources/SwiftFoundation/POSIXFileSystemStatus.swift:28:45: error: thrown expression type 'POSIXError' does not conform to 'ErrorType'
throw POSIXError.fromErrorNumber!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.