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

  Переглядів 18,115

Paul Hudson

2 роки тому

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...

Paul Hudson
Paul Hudson Рік тому
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.
Sebastian Rodriguez
Sebastian Rodriguez 28 днів тому
can you update it with the latest Swift version? Thank you!
Daryl Wong
Daryl Wong Рік тому
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?
Dimitri Brukakis
Dimitri Brukakis Рік тому
Cool as always! Thank you very much!
LHSgoatman Рік тому
For anyone who wanted the uuidString typed out let uuid = UUID(uuidString: "5A4BCFCE-174E-4BAC-A814-092E77F6B7E5")
Prashant Gaikwad
Prashant Gaikwad Рік тому
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?
Yvan Frey
Yvan Frey Рік тому
This was so much fun! Thank you Paul! A few things changed since it was published. I made the following changes to get it to work withXcode 11.4 beta: BindableObject is now ObservableObject @ObjectBinding is now @ObservedObject var didChange = PassthroughSubject() and didChange.send() can be removed by adding @Published in front of var lastDistance = CLProximity.unknown
hitlab Рік тому
Very helpful thanks! Is there another Tutorial on your channel that teaches how to create an app that transmits as an IBeacon.?
rob janson
rob janson Рік тому
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
rob janson
rob janson Рік тому
I am creating the app on a new macbook Air running ios 10.15.3; XCode 11.3.1 and ios 13.3
Mauro Junior
Mauro Junior Рік тому
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()
Roberto Arenas
Roberto Arenas Рік тому
Thank very much for your help!!!!!! this comment made my day
Alan Cutler
Alan Cutler Рік тому
I knew that BindableObject was depreciated, and thanks for the code it got my app working.
Jesse Рік тому
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.
Canispater Christmas aka Jeff
Canispater Christmas aka Jeff 2 роки тому
I believe "didChange.send()" [one set of parens] works now.
Canispater Christmas aka Jeff
Canispater Christmas aka Jeff 2 роки тому
... but great tutorial!
Mark Patterson
Mark Patterson 2 роки тому
As soon as i get round to trying it out, BindableObject is deprecated. D'Oh. The bleeding edge.
Michał Sułkiewicz
Michał Sułkiewicz Рік тому
@Mark Patterson 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.
Mark Patterson
Mark Patterson 2 роки тому
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!
Ken Law
Ken Law 2 роки тому
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.
Mark Patterson
Mark Patterson 2 роки тому
I like the way your physical device uses 24h time. Now we know that you stay up late to do these videos ;)
Guitaripod 2 роки тому
This was awesome
Элёржон Кимсанов
Элёржон Кимсанов 2 роки тому
Hi! Why you call super.init before setting all values?
Элёржон Кимсанов
Элёржон Кимсанов 2 роки тому
Guitaripod That’s why I am confused) medium.com/@dineshk1389/swift-why-super-init-is-called-after-setting-all-self-properties-d6827e9f4eb2
Guitaripod 2 роки тому
Элёржон Кимсанов I think super always comes first.
Элёржон Кимсанов
Элёржон Кимсанов 2 роки тому
Guitaripod Well, I mean - why super.init called before setting values of child. Not after.
Guitaripod 2 роки тому
Cause the new class is inheriting from NSObject and it's default init() method, so "override" must be used. I think
Nigel Gee
Nigel Gee 2 роки тому
Note that in Xcode 11.0 beta 4 “didChange” is now “willChange”
Andy Miller
Andy Miller 2 роки тому
If you had a course on full production ready swiftUI apps i would definitely buy it.
Brian bkcodes
Brian bkcodes 2 роки тому
Great stuff -- thanks for the demonstration at 14:41 of how to do the custom view modifier
Nathan Furman
Nathan Furman 2 роки тому
I spent amazing 22 minutes of my live while watching this tutorial
Marc Aupont
Marc Aupont 2 роки тому
Loved it!! Really nice pro tip with the ViewModifiers
Marcin Frydrych
Marcin Frydrych 2 роки тому
This tutorial is for advanced developers.
Timothy Barnard
Timothy Barnard 2 роки тому
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
Paul Hudson
Paul Hudson 2 роки тому
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.
Robert Petras
Robert Petras 2 роки тому
Thanks Paul again! 👍 For anyone else who is looking into this app, this is the Project 22 (Detect-a-Beacon) in the Hacking with Swift book (www.hackingwithswift.com/store). In that book Paul recommends us install the “Locate Beacon” AppStore app on our iPad or iPhone, because it comes with an iBeacon transmitter built in. 🚥 Happy coding!
skjk 2 роки тому
Why is CLLocationManager an optional?
jian ma
jian ma Рік тому
I know, he initialized it in the default initializer anyway.
abdou ett
abdou ett 2 роки тому
Thanks for this amazing tuto! Plz, should always pass Never instead of Error in PassthroughSubject ?
Frédéric ADDA
Frédéric ADDA 2 роки тому
This is cool because it's very effective in a short amount of time. 20 mn is a perfect duration for me to learn.
PIP POP 2 роки тому
Why not using switch?
Vincent O'Sullivan
Vincent O'Sullivan 2 роки тому
These are quick and dirty coding examples of SwiftUI. They shouldn't be taken as examples of coding best practice.
antoineweb1 2 роки тому
what’s the beacon app you are using on iPad? thanks
Göran Lilja
Göran Lilja 2 роки тому
Locate Beacon - Locate Beacon by Radius Networks apps.apple.com/se/app/locate-beacon/id738709014
Timothy Barnard
Timothy Barnard 2 роки тому
antoineweb1 I used an app called locate
Nathaniel Fredericks
Nathaniel Fredericks 2 роки тому
In his Hacking With Swift series, he used the "Locate Beacon" app by Radius Networks.
Don Whiteside
Don Whiteside 2 роки тому
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!
Mücahit Katırcı
Mücahit Katırcı 2 роки тому
Great Job Paul !!
fawad farooq
fawad farooq 2 роки тому
Thanks Paul !
IoT and Indoor Tracking with Raspberry Pi
Esri Events
Переглядів 82 тис.
МастерШеф 11 сезон. Выпуск 2 от 04.09.2021
Переглядів 1,1 млн
Співають всі - All Together Now Ukraine
Переглядів 286 тис.
Steve Jobs Insult Response - Highest Quality
Jonathan Field
Переглядів 10 млн
Create ML for Everyone
Paul Hudson
Переглядів 15 тис.
I built the same app 10 times // Which JS Framework is best?
Переглядів 444 тис.
Debugging Swift Memory Issues with Xcode and Profiler
Make School
Переглядів 22 тис.
But how does bitcoin actually work?
Переглядів 10 млн
МастерШеф 11 сезон. Выпуск 2 от 04.09.2021
Переглядів 1,1 млн
Співають всі - All Together Now Ukraine
Переглядів 286 тис.
Мой кот точно пытается меня убить
Переглядів 2,8 млн
CheAnD TV - Андрей Чехменок
Переглядів 431 тис.