I was an *****, the tutorial was garbage, sorry...
Post
Replies
Boosts
Views
Activity
I think there is a time limit on how long one can actually run the app on a physical device with a free account, I used to have a free account and after some time the app will just stop running. I believe your only option now is to run it on a simulator or buy the Developer subscription...or if you find someway to delete the current certificate and reinstall a new one...
I think I see what you mean...
import ExtraConverter
let encoder = Encoder.init(source: myString)
then in the package's contents make the class and constructors public is what solved the issue...
I did test the paste option when something was copied to the clipboard. It worked naturally...I don't know why I was trying to get it to function when there was nothing on the paste board...
Thank you for the answer. I am working on an iOS 13 project and I am not even getting the paste option for an empty UITextField module.
I have already decided on removing that button until I get things working. I think I will convert it to 16 byte Data value later on...
Here is the code to decode hexadecimal and binary:
private func decodeHexString(source: String) -> Void {
let data = Data(fromHexEncodedString: source)
let altData = Data(fromHexEncodedString: "74647374")
let string = String(data: ((data) ?? altData)!, encoding: .utf8)
// Print the result
resultOutput.text = string
}
private func decodeBinaryString(source: String) -> Void {
// Split the binary string into 8'ths
let newString = source.separate(every: 8, with: "\n")
let byteArray = newString.components(separatedBy: .whitespacesAndNewlines).compactMap {UInt8($0, radix: 2)}
if let string = String(bytes: byteArray, encoding: .utf8) {
resultOutput.text = string
} else {
displayErrorMessage(title: "Encoding", message: "Bad Binary Encoding..."); return
}
}
Also, there is this extension to Data:
extension Data {
// From http://stackoverflow.com/a/40278391:
init?(fromHexEncodedString string: String) {
// Convert 0 ... 9, a ... f, A ...F to their decimal value,
// return nil for all other input characters
func decodeNibble(u: UInt16) -> UInt8? {
switch(u) {
case 0x30 ... 0x39:
return UInt8(u - 0x30)
case 0x41 ... 0x46:
return UInt8(u - 0x41 + 10)
case 0x61 ... 0x66:
return UInt8(u - 0x61 + 10)
default:
return nil
}
}
self.init(capacity: string.utf16.count/2)
var even = true
var byte: UInt8 = 0
for c in string.utf16 {
guard let val = decodeNibble(u: c) else { return nil }
if even {
byte = val << 4
} else {
byte += val
self.append(byte)
}
even = !even
}
guard even else { return nil }
}
}
No, I need it to detect one or the other...Like if I enter a binary string of "01110100011001010111001101110100" which is "test" in string format, I need for the isStringBinary() boolean method run and if the string is hexadecimal, say, "74657374" which is "test" in hexadecimal, then I need the isStringHex() boolean method to run...I don't know why it is stopping at "Hexadecimal" when I insert a binary string though...I was thinking about adding a return after each detect...
Here is the whole code for the button action method
@IBAction func btnAutoCheckString(_ sender: Any) {
let source = sourceString.text!
if isStringBinary(source: source) {
decodings.selectRow(2, inComponent: 0, animated: true)
decodeBinaryString(source: source)
}
if isStringHex(source: source) {
decodings.selectRow(1, inComponent: 0, animated: true)
decodeHexString(source: source)
}
}
// Applying Claude31's methods
private func isStringHex(source: String) -> Bool {
let reg = try! NSRegularExpression(pattern: "(0x)?([0-9a-fA-F]{16})")
let ran = NSRange(location: 0, length: source.count)
if (reg.firstMatch(in: source, options: [], range: ran) != nil) {
return true
}
return false
}
private func isStringBinary(source: String) -> Bool {
/*
let reg = try! NSRegularExpression(pattern: "([01]{2})")
let ran = NSRange(location: 0, length: source.count)
if (reg.firstMatch(in: source, options: [], range: ran) != nil) {
return true
}
return false
*/
let chars : Set<Character> = Set(source)
let isValidBin = chars.isSubset(of: ["0", "1"]) && chars.count >= 1
return isValidBin
}
Developing on MacOS is pretty simple and straight forward, it would seem that the environment is setup so that one does not have to code much (in my opinion), one can just drag and drop features into the ViewController environment. The layouts are simple enough to use except when you get to constraining a Scrolling module.
Anyway, if you really want to start learning how to program SwiftUI/Swift/Mac, iOS apps. Start with something simple. Mine starter was a payroll calculator. Anyway, start with something simple, figure out what you want your program to do, design the UI (inputs, buttons, outputs, etc) then, switch to coding the app, approach it little by little (based on your current level of understadning), and begin with plugging in your UI components to your main script file. That is how I started out learning...
[ this might not be the response you are looking for but I stumbled onto this thread and had to throw in my 2 cents... ]
Thank you for the replies, both solutions worked the way they intend to work. OOPer's solution would be the best to implement in a separate module.
Thank you for the help and baring with me. I have completely forgotten about the Main.storyboard deletion 😂.
I was messing with the constraints, trying to fix the constraints using auto-layout, other than that, I didn't do much of anything. I did accidentally delete my Main.storyboard though...I think that would have been the cause.
Update: I began a new project iteration, String Converter 2, and I did the same thing as I did last time and now the program works...so...I don't know what happened, but now the program works. I have kept the original (broken) program just in case anyone is able to solve the problem with the first (original) program.
I tried OOPer's solution but to no avail, I have screenshot the important bits which includes the code and the main view along with the Outlet connection for UIScrollView. Everything seems to be in tack...but I don't know what's wrong...I will start another iteration of this project to test out if the view is actually broken.
Edit: Cannot attach images so, I will attach the code for FirstViewController.swift
import UIKit
class FirstViewController: UIViewController, UIScrollViewDelegate {
// MARK: Outlet prototype initializations
@IBOutlet weak var mainScrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
// For scroll view scroll functionality
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
mainScrollView.contentSize = CGSize(width: mainScrollView.contentSize.width, height: mainScrollView.contentSize.height)
mainScrollView.decelerationRate = UIScrollView.DecelerationRate.fast
}
}