Giter Site home page Giter Site logo

guillermomuntaner / burritos Goto Github PK

View Code? Open in Web Editor NEW
1.3K 28.0 43.0 104 KB

A collection of Swift Property Wrappers (formerly "Property Delegates")

License: MIT License

Swift 95.06% Ruby 4.94%
swift property-wrapper swift-package ios swift-package-manager ios-swift cocoapods learning

burritos's People

Contributors

guillermomuntaner avatar kylebshr avatar lucianopalmeida avatar own2pwn 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

burritos's Issues

@Lazy* property wrappers are not thread safe

The @Lazy and @LazyConstant property wrappers do not appear to be thread safe. That is, if two threads attempt to hit the initial getter at the exact same time, they will both attempt to initialize the value. Running the initializer multiple times can have the adverse effect of executing the "expensive operation" multiple times, which is not a good thing.

Note: This only would happen if the @Lazy objects are accessed in multiple threads. For UIKit initializers, everything must be done on the main (synchronous) thread, and so we don't have this issue.

The "standard" solution for such a case is creating a concurrent queue, and doing the work within the getter in a queue.sync{} block, and (for the non-constant @Lazy implementation), putting the setter into an async{} .barrier
to ensure the reads and writes are synchronized. This would require that a DispatchQueue be created for every @Lazy property, but this has the side-effect of possibly creating many, many GCD queues, which isn't needed for the UIKit exception I mentioned above. This might require maintaining a pool of thread objects, assigned to each @Lazy object, but we're now adding even more complexity to what should be a simple property wrapper.

So, my suggestion is to provide two additional property wrappers to have a total of four @Lazy style objects:

  1. @Lazy -- Current modifiable implementation
  2. @LazyConstant -- Current constant implementation
  3. @LazyQueue -- @Lazy + barrier queues
  4. @LazyQueueConstant -- @LazyConstant + synchronous queues

An even better implementation would allow the passing of an OptionSet to supply [.constant, .queue] to the initializer, but that makes the @Lazy(flags: [], wrappedValue: { ... } var foo quite complex to write.

Carthage support

Hello.
Thank you for Burritos.
As I can see Burritos does not support Carthage. I think it will be good to add this feature.

Lazy property wrapper doesn't work with closures

Simple playground test:

class Test {
    lazy var myLazyVar: Void = {
        print("crazy")
    }()
}

print("Initialize: ")
var test = Test()
print("call first")
test.myLazyVar

will print:

Initialize: 
call first
crazy

but then you have:

class Test {
    @Lazy var myLazyVar: Void = {
        print("crazy")
    }()
}

print("Initialize: ")
var test = Test()
print("call first")
test.myLazyVar

which will print:

Initialize: 
call first

Rename Expirable as Cached

Wouldn't it be intuitive to have @Expirable as @cached instead? Coz token usually isn't expired(if we're talking from the app's point of view) i.e. the server manages token's life time and client simply caches it for limited time.

@Lazy does not work with self

One of the main reasons I use lazy is when I need access to self, lazy allows me to defer creation of the property to access-time (i.e. when self is available).

Is there a way to make @lazy support self?

The deploy target version is too high in the podspec

The deployment target seems too high:

  s.ios.deployment_target = '13.0'
  s.osx.deployment_target = '10.15'
  s.tvos.deployment_target = '13.0'
  s.watchos.deployment_target = '6.0'

The wrapper is a compiler feature, not the runtime. Is it right?

Could it be possible using a property wrapper with Decodable and optional value?

Hi @guillermomuntaner , thanks your great repo, It's very helpful for swift developing.

It' seems that you have learn a lot about using property wrapper to provide convenient feature.
Could you do me a favor, for helping me resolve the problem, just like what title says.

The situation is that, when using Decodable
We need to know every property that is optional or not to define the model
That's too hard to ensure you get what you want
Sometime server just update, you fail to parse the data

But like other framework as HandyJSON, they provide default value for model
We can safely define every property as non-optional with that

Is there a way to achieve this with Property Wrapper for Decodable?
Thanks in advance

No such module 'Burritos' when installing via SPM

Version 11.2.1 (11B53)
Device: iPhone 11 and iPhone Pro Max Simulator
Version: 0.0.3
image

image

//
//  ContentView.swift

import Burritos // No such module 'Burritos'
import SwiftUI

struct ContentView: View {
    @LateInit test: String
    var body: some View {
        Text("Hello, World!")
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

The module does not load and I cannot use any of the features.

Looking for ideas!

Hello everyone!

In order to extend the collection I am looking for new fresh ideas.

Thanks.

Getting compile error when using @LazyConstant

I used Swift 5.1/Xcode 11.1 to reproduce this issue.
Consider the following code:

protocol P {
    func f()
}

struct S: P {
    func f() { }
}

func f(p: P) {
    p.f()
}

class C {
    @LazyConstant
    var s: S = {
        return S()
    }()

    func g() {
        f(p: s)
    }
}

Getting the following error: Expression type '()' is ambiguous without more context. To fix it replace f(p: s) with f(p: s as P). But as for me this is a bug.
I also created an issue at https://bugs.swift.org.

AtomicWrite Collections

First of all, amazing collection of Property Wrappers you have here!! Truly a great resource! So thank you!! ๐ŸŽ‰

One thing I noticed, is the AtomicWrite property wrapper doesn't handle collections the best. I could be thinking about this wrong, but when accessing the underlying properties or functions, it doesn't do it in an Atomic way as far as I can tell. Since collections are just pointers to other items in memory, accessing those other items is not handled in an atomic way.

What are your thoughts on this? Do you think there is potential for maybe an extension on top of AtomicWrite that would help access the items in a collection in an Atomic way?

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.