ibeacon app development using swift - ios

everyone, I am a new one to iOS app development using swift.
I am studying a ibeacon app sample code which downloaded from the https://github.com/SelimSalihovic/CityOS-iBeacon-Swift-Tutorial.
while I was running the code, there are errors in the code as shown the following page, could you help me how to solve it, please! Thanks in advance!

The first one is easily solveable by unwrapping the value (the exclamation mark)
NSUUID(UUIDString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D")!
Second and third error are due to the beacons array not declaring the content's type (AnyObject means it can't be any class, which is not guaranteed to have the properties the code is looking for) so just go to line 16 and make the following change
var beacons : [CLBeacon] = []
However this will still not compile because the LocationServices framework hasn't been imported in the project, to do so just add
import CoreLocation
There will be some more errors now, specifically at line 26 and 55 in BeaconTableViewController
Fix-It has the right suggestion for these, basically you need to cast note.object by adding as! [CLBeacon] and remove the unwrapping on switch proximity because the value isn't optional
The code now compiles properly for me, I'm not sure it will work because I can't test right now, but it should be a step in the right direction
Good luck with your journey in iBeacons, they're a pretty fun technology to work with

Related

Realm crash on iOS 10 with 'String'

I have recently released a new version of our app and during beta testing, it's crashing on all iOS 10 devices but not other versions. Since we have Crashlytics, we found a strange crash message in the backend that we can confirm is the reason all iOS 10 crashing since it's 100% iOS 10 and there's like 40 of them.
It reads as follows:
Fatal Exception: RLMException
Property Article.id is declared as String, which is not a supported managed Object property type. If it is not supposed to be a managed property, either add it to ignoredProperties() or do not declare it as #objc dynamic. See https://realm.io/docs/swift/latest/api/Classes/Object.html for more information.
And here's the object:
class Article: Object {
#objc dynamic var id: String = UUID().uuidString
// others...
override static func primaryKey() -> String? {
return "id"
}
}
As you can see, this is perfectly nomral and runs fine on other iOS. In Realm's doc, it LITERALLY SAYS to use String with #objc dynamic and there's no way it's unsupported. I suspect there's nothing special about Article.id, and since Article starts with A, it happens to be the first String property of all realm Objects. Maybe somehow all Strings stopped working on iOS 10?
Can anyone offer some advice or insights?(Please don't say things like drop iOS 10 support. For now, we need it.)
We ran into the same issue a couple of times, trying to drag Realm fully into Swift. This is not really the answer but more of a workaround we've had success with when needing backward compatibility.
It's an ObjC object, not Swift.
There's something going on with the bridging, perhaps conforming to NSCopy'ing or something along those line, so just change it to read
#objc dynamic var id = NSUUID().uuidString
See the Getting Started Guide in the Models section which calls for using NSUUID
NSUUID: An object representing a universally unique value that bridges
to UUID; use NSUUID when you need reference semantics or other
Foundation-specific behavior.
Turns out it was a Realm's bug. We happen to have another app that runs just fine on iOS 10, and after some inspection we realized that it was using Realm 4.3.2, instead of 4.4.1. After we downgraded Realm to 4.3.2, this problem disappeared.

How to implement firebaseUI in IOS

I new to IOS Development.I am basically android developer
I want to implement firebaseUI for login using mobile number and email
I got doc here https://firebase.google.com/docs/auth/ios/firebaseui?authuser=0. But i am getting compiletime error..below I mention
My AppDelegate file
my ViewController class
if I comment this line authUI.delegate = self above line getting wrong below I add image...
authUI is a Swift optional, which means it can be nil (null). In order to use optionals, you must unwrap them with the '?' sign. So your code can be simply fixed with:
authUI?.delegate = self
If authUI is nil, the code will do nothing, whereas in Java it would cause a null pointer exception. You may unwrap it with '!' instead, which will cause a runtime error if authUI is nil.
Tip: you can click on the red error or yellow warning icons to see and apply suggested fixes, much like Alt-Enter on Android Studio. Do not rely too much on those, sometimes the automatic fixes become a mess. :)

Use of unresolved identifier - app development with Swift Project 2

Sorry - I realise this is a complete beginner question, but I've googled for half a day now and still can't resolve the issue myself.
I'm using xCode 8.3 and trying to complete the apple - app development with swift course - end of unit project 2. I'm told (by the Apple book) I should be able to run the app without build failures, even if it isn't finished.
I get an unresolved identifier error when I add the following code to my ViewControler file, inside the class ViewController: UIViewController.
func updateUI() {
correctWordLabel.text = game.formattedWord
scoreLabel.text = "Wins: \(totalWins), Losses: \(totalLosses)"
treeImageView.image = UIImage(named: "Tree \(currentGame.incorrectMovesRemaining)")
}
xCode suggests I change it to Game.formattedWord, but when i do get 'Instance member 'formattedWord' cannot be used on type 'Game' ViewController.Swift'.
Could someone please help?
I've checked the sample code from Apple about 100 times and they are def saying it should be game.formattedWord in the code.
Thank you!
Try correctWordLabel.text = currentGame.formattedWord
I think it’s a typo.
Earlier in your code you create an instance of the Game struct called currentGame so you are accessing the formattedWord variable inside that instance. That’s why you couldn’t change it to Game. Game is like the blueprint of the struct. currentGame is your actual ‘thing’ Hope that makes some sense.

Stanford calculator app crashes with error "unexpectedly found nil"

I'm new to programming and I've started taking the stanford course on iTunes U for making an iPhone 8 app. They're using Xcode 6 and Swift 1 while I'm in El Capitan using Xcode 7 and Swift 2. I've found a few differences in code that Xcode has been able to pick up on and help me correct ("println" is now "print" for example), but I'm getting tripped up on one particular part of the code:
var displayValue: Double {
get {
return NSNumberFormatter().numberFromString(display.text!)!.doubleValue
}
set {
display.text = "\(newValue)"
userIsInTheMiddleOfTypingANumber = false
}
}
I've double checked several times to make sure this is exactly how the teacher wrote it. His built correctly and functioned correctly, while mine builds correctly, but shows this fatal error when I try to operate it, "unexpectedly found nil while unwrapping an Optional value" (see screenshot for all the details).
Screenshot of the error
I've been looking around the internet and found a few similar examples, including one on this site (Stanford Calculator app keeps crashing), but after trying everything that was suggested I concluded that something must be unique in my system or I'm operating in a new Xcode/Swift environment than the others that had this problem. None of the solutions have resolved the problem, and all of them added errors of their own.
In responding to someone else's question someone suggested that we use this code to ensure that if "nil" is returned by "display" that it will provide "0" instead:
return (NSNumberFormatter().numberFromString(display.text) as? Double) ?? 0
I tried this, but it only gave me more errors, some seem to be related to Swift 2 (it required a comma after double, wanted me to unwrap display.text, and complained that there was an expected expression missing—maybe the suggested code was good in Swift 1??).
I've double checked several times to make sure this is exactly how the teacher wrote it. His built correctly and functioned correctly, while mine builds correctly, but shows this fatal error when I try to operate it, "unexpectedly found nil while unwrapping an Optional value"
I suspect that display is an IBOutlet property that needs to be connected to something in the user interface, probably a text field. If it's not connected, then even though your code is exactly the same, you'll get nil when you try to use its text property, and unwrapping that will cause the error you're seeing.
Whether or not the advice above actually solves your problem, what you really need to do is to set a breakpoint a line or two before the spot where the crash occurs and step through the code. Look at the variables involved and figure out where that nil value is coming from. You can work backward from there and figure out why the thing that you expect not to be nil is, in fact, nil. Learning to work that way will help you work out these kinds of problems when they occur (and they will occur again).
Not sure if you've found the answer or not by now, but I ran into a similar problem this morning and thought I'd share what I found.
While debugging, I entered two console logs to a simplified version of my operate like so:
case "x": if operandStack.count >= 2 {
print(" display before popping is: \(display.text!) ")
displayValue = operandStack.removeLast() * operandStack.removeLast()
print(" display after popping is: \(display.text!) ")
enter()
}
Display after popping came up as "newValue". I couldn't figure out what that meant at first, but realized that my issue is the setter. newValue is an optional that should be unwrapped i.e. "(newValue)!"
P.S. I opted to return:
return (display.text! as NSString).doubleValue
in my get.
Also, since newValue is unwrapped, keep in mind it will crash if display is set to nil.

Error adding enum type to Swift Array

I'm trying to add an enum type to an Array and am getting an error. I am able to add a String and other types, but this enum is failing. Does anyone know what might be going wrong here?
enum Domain {
case Default
}
let domains: Array<Domain> = [.Default]
Thread 1:EXC_BAD_INSTRUCTION(code=EXC_i386_INVOP, subcode=0x0)
This is definitely an Apple bug - log it! https://bugreport.apple.com
Add a second case to your Enumeration (e.g. case Other) and see that the error no longer occurs. Something crazy is going on in Swift when an Enumeration has only one case.
It looks like, at least in my playing with a playground, if the enum definition contains the word 'Domain' at all anywhere in the name the enum fails to compile/work.
I think it's just a compiler bug on Apple's part... If I have the following code, and only this code, everything runs fine:
var points = TestEnum[]()
points += TestEnum.TestValue
enum TestEnum {
case TestValue
case SecondTestValue
}
However, I have code above that code (a simple RPN implementation, but it doesn't matter). The RPN code runs fine by itself. But with the TestEnum code in there, the RPN code crashes. The crash is an EXC_BAD_ACCESS and crashes on a random line and different address based on what lines of code are in the program (I'm guessing because the offsets in the executable change). For instance, I added a println after the points += call, and it crashed at a different part of my RPN code.
Both the RPN code and the TestEnum code run fine by themselves. This is almost definitely an Apple bug.

Resources