SwiftUI Tutorial: Build an iBeacon detector with object binding and custom modifiers

  Переглядів 24,476

Paul Hudson

Paul Hudson

4 роки тому

Ready to get started with SwiftUI? In this tutorial you'll learn how to build an app that can detect nearby iBeacons, all using @ObjectBinding and a custom view modifier so we can avoid repeating code.
For more information on SwiftUI, see my free online reference guide SwiftUI By Example: www.hackingwithswift.com/quic...

КОМЕНТАРІ: 58
@twostraws
@twostraws 4 роки тому
Watch next: SwiftUI Tutorial: Build a Core ML app with stacks, steppers, and date pickers - ukposts.info/have/v-deo/l3GHpmaro4apqas.html Questions? Comments? Tweet me @twostraws.
@marcaupont9145
@marcaupont9145 4 роки тому
Loved it!! Really nice pro tip with the ViewModifiers
@brianbkcodes1449
@brianbkcodes1449 4 роки тому
Great stuff -- thanks for the demonstration at 14:41 of how to do the custom view modifier
@user-sq5xv6dr1v
@user-sq5xv6dr1v 4 роки тому
I spent amazing 22 minutes of my live while watching this tutorial
@fawadfarooq
@fawadfarooq 4 роки тому
Thanks Paul !
@fredericadda
@fredericadda 4 роки тому
This is cool because it's very effective in a short amount of time. 20 mn is a perfect duration for me to learn.
@dimiutube
@dimiutube 3 роки тому
Cool as always! Thank you very much!
@abdouett3676
@abdouett3676 4 роки тому
Thanks for this amazing tuto! Plz, should always pass Never instead of Error in PassthroughSubject ?
@hitlab
@hitlab 4 роки тому
Very helpful thanks! Is there another Tutorial on your channel that teaches how to create an app that transmits as an IBeacon.?
@mucahitkatrc3285
@mucahitkatrc3285 4 роки тому
Great Job Paul !!
@iOSTechie
@iOSTechie 3 роки тому
Hi Paul, is it possible to scan and broadcast from the same app at the same? Like both app should display the message that this iPhone is near you?
@QuiiKSyyntax
@QuiiKSyyntax 4 роки тому
If you had a course on full production ready swiftUI apps i would definitely buy it.
@GameCrawl
@GameCrawl 3 роки тому
Hi, what is the App that you have used to transmit the iBeacon info in the iPad. The 123,456 is tied to the beacon? So if I got a real beacon, I would need to tie it to these two major minor numbers for broadcasting out?
@kevinperugini64
@kevinperugini64 9 місяців тому
Could you recommend me a cheap one to do these tests? Thank you❤
@nigelgee3576
@nigelgee3576 4 роки тому
Note that in Xcode 11.0 beta 4 “didChange” is now “willChange”
@BaltorAirsoftSniper
@BaltorAirsoftSniper 2 роки тому
can you update it with the latest Swift version? Thank you!
@sudhakarkrishnan1203
@sudhakarkrishnan1203 Рік тому
can we scan beacons without knowing uuid like near beacons we can list in out screen.
@Jesse-xq7jb
@Jesse-xq7jb 4 роки тому
Whew... this one was fairly advanced. But I pulled up the apple docs for beacons, and now I'm glad I went through it anyways.
@arielitto100
@arielitto100 5 місяців тому
Hi Paul, is it possible to work with beacons other than Apple's? I have a Chinese beacon (feasycom) and would like to communicate with it.
@guitaripod
@guitaripod 4 роки тому
This was awesome
@gambiahero
@gambiahero 4 роки тому
Hey Paul! I loved your videos and it helped me a lot, but I came across some issues. The state did not change and the new state of distance did not reach the detector. I was able to solve it when I changed these lines of code. First BindableObject was changed to ObservableObject and ObjectBinding is now ObservedObject Second it worked for me when i changed let didChange = PassthroughSubject() to let objectWillChange = ObservableObjectPublisher() and didChange.send() to self.objectWillChange.send()
@ajcutler54
@ajcutler54 3 роки тому
I knew that BindableObject was depreciated, and thanks for the code it got my app working.
@rober_6
@rober_6 3 роки тому
Thank very much for your help!!!!!! this comment made my day
@samdosi6829
@samdosi6829 Рік тому
i know it has been 3 years, but i just wanted to let u know that ur comment saved me hours of debugging, thank you !
@fredylopez529
@fredylopez529 Рік тому
I appreciate you BRO!
@robjanson7906
@robjanson7906 4 роки тому
Great content, very useful for me. I don't understand the last minute or so of this when testing the app with a beacon. Everything works for me up to that point but I cannot get the app to respond to my beacon. I am using an estimote LTE beacon, I have also tried using my iphone 11 using the nRF App to advertise itself as a beacon with no luck. What am I doing wrong? Thanks in advance
@robjanson7906
@robjanson7906 4 роки тому
I am creating the app on a new macbook Air running ios 10.15.3; XCode 11.3.1 and ios 13.3
@TheMaverickologist
@TheMaverickologist 4 роки тому
Why is CLLocationManager an optional?
@jianquanma
@jianquanma 4 роки тому
I know, he initialized it in the default initializer anyway.
@marcinfrydrych5319
@marcinfrydrych5319 4 роки тому
This tutorial is for advanced developers.
@markaurelius61
@markaurelius61 4 роки тому
I like the way your physical device uses 24h time. Now we know that you stay up late to do these videos ;)
@markaurelius61
@markaurelius61 4 роки тому
As soon as i get round to trying it out, BindableObject is deprecated. D'Oh. The bleeding edge.
@kenlaw3376
@kenlaw3376 4 роки тому
Agreed, this tutorial does not work anymore. I hope Paul would post a link to the code updates that would correct the deprecations and update the code.
@markaurelius61
@markaurelius61 4 роки тому
I just swapped in the new versions of the keywords and it works in that form. Then I was able to play around with structuring the code. SwiftUI is fun!
@michasukiewicz1172
@michasukiewicz1172 4 роки тому
@@markaurelius61 Now (Version 11.1 (11A1027)) it is enough to use keyword @Published for the lastDistance: @Published var lastDistance = CLProximity.unknown (in BeaconDetector class) and then call wrap it as an @OservedObject in the CointentView struct: @ObservedObject var detector = BeaconDetecter(). All bindings are done automatically in SwiftUI framework.
@pippop9583
@pippop9583 4 роки тому
Why not using switch?
@vjosullivan
@vjosullivan 4 роки тому
These are quick and dirty coding examples of SwiftUI. They shouldn't be taken as examples of coding best practice.
@timb3970
@timb3970 4 роки тому
Would it not be better to create a stringValue and colorValue variables inside an extension of CLProximity or inside the BeaconDetector class. This would clean up the ContentView body a lot. Great tutorial anyway, Thanks. I love SwiftUI
@twostraws
@twostraws 4 роки тому
While I can understand why you might take that approach, in my own code I wouldn't allow the model to dictate how the view should look.
@antoineweb1
@antoineweb1 4 роки тому
what’s the beacon app you are using on iPad? thanks
@DonWhitesideisMe
@DonWhitesideisMe 4 роки тому
Exactly what I opened up the comments to ask. I’m sure there’s plenty on the store but if you have one you like, Paul, save is all the trouble of choosing!
@timb3970
@timb3970 4 роки тому
antoineweb1 I used an app called locate
@GoranLilja
@GoranLilja 4 роки тому
Locate Beacon - Locate Beacon by Radius Networks apps.apple.com/se/app/locate-beacon/id738709014
@LHSgoatman
@LHSgoatman 3 роки тому
For anyone who wanted the uuidString typed out let uuid = UUID(uuidString: "5A4BCFCE-174E-4BAC-A814-092E77F6B7E5")
@CanispaterChristmas
@CanispaterChristmas 4 роки тому
I believe "didChange.send()" [one set of parens] works now.
@CanispaterChristmas
@CanispaterChristmas 4 роки тому
... but great tutorial!
@kimsanov
@kimsanov 4 роки тому
Hi! Why you call super.init before setting all values?
@guitaripod
@guitaripod 4 роки тому
Cause the new class is inheriting from NSObject and it's default init() method, so "override" must be used. I think
@kimsanov
@kimsanov 4 роки тому
Guitaripod Well, I mean - why super.init called before setting values of child. Not after.
@guitaripod
@guitaripod 4 роки тому
Элёржон Кимсанов I think super always comes first.
@kimsanov
@kimsanov 4 роки тому
Guitaripod That’s why I am confused) medium.com/@dineshk1389/swift-why-super-init-is-called-after-setting-all-self-properties-d6827e9f4eb2
@Silver_Samurai
@Silver_Samurai 2 роки тому
I am really struggling with the didChangeAuthorization status func, when I input .authorizedWhenInUse I get an error & for some reason saying "status not in scope" I just cant find the solution, is there someone on the feed who could point me in the right direction please? thank you.
@Drew287
@Drew287 Рік тому
You have to use the deprecated version. I didn't use the new version on the function
@jkardach
@jkardach 9 місяців тому
Great Tutorial. It appears Combine has changed, and BindableObject protocol (not recognized anymore) has been replaced by ObservableObject. With ObservableObject, the didChange variable can be deleted (Not needed). The @objectBinding is replaced by @Published: @Published var lastDistance = CLProximity.unknown No need to call didChange.send(()) (this is done automagically) . Last in the view you need to declare the BeaconDetector using @ObservedObject and not @ObjectBinding: @ObservedObject var detector = BeaconDetector(). Seems to have gotten simpler.
@GGGGGG-qj2un
@GGGGGG-qj2un 7 місяців тому
Thanks.
@YuChang-Chu
@YuChang-Chu 5 місяців тому
Super helpful, thx.
8 Common SwiftUI Mistakes - and how to fix them!
28:05
Paul Hudson
Переглядів 49 тис.
🛑 Друзья всегда выручают
00:12
Арсений Бардаш
Переглядів 10 млн
Building a scalable, modularized, testable app from scratch
21:31
Android Developers
Переглядів 147 тис.
Swift API Calls for Beginners (Networking) - Async Await & JSON
25:35
5 Steps to Better SwiftUI Views
31:19
Paul Hudson
Переглядів 54 тис.
Master BLE Basics in Just 10 Minutes: The Ultimate Guide!
9:15
Novel Bits
Переглядів 84 тис.
Fundamentals of Compose Layouts and Modifiers - MAD Skills
11:56
Android Developers
Переглядів 76 тис.
Easy Custom Animated Tab Bar in SwiftUI Tutorial for iOS 15
13:20
You might not need useEffect() ...
21:45
Academind
Переглядів 110 тис.
iPhone 19?
0:16
ARGEN
Переглядів 3,1 млн
If you do wire soldering with paste, soldering can be done very easily
0:26
Tech Electronics BD
Переглядів 1,5 млн